weixin_33690963 2014-09-05 05:42 采纳率: 0%
浏览 38

jQuery ajax搜索问题

I'm working on the functionality of searching images in a ajax based div which is also loading the data in a div container.

I have the following code and it works fine, if I am not executing any search criteria. If I add search, it throws error in all browsers in jquery min.js file. I am using version 1.11.1 for this. Different browsers show different errors.

jQuery code:

$(document).ready(function() {
    $("#finder").blur(executeFunction);
    function executeFunction(page) {
        page = typeof parseInt(page) == "number" ? page : 1;
        $.ajax
        ({
            type: "POST",
            url: "find.php",
            data: {
                page: page,
                search: encodeURIComponent( $('#finder').val() )
            },
            success: function(msg)
            {
                $(document).ajaxComplete(function(event, request, settings)
                {
                    $("#container").html(msg);
                });
            }
        });
    }
    executeFunction(1);
});

HTML code:

<input type="finder" id="finder" />

Without search all work fine..

Here is the error I received in Firefox:

TypeError: 'initUIEvent' called on an object that does not implement interface UIEvent.

...unction(a,b){var c,d=[],e=function(a,b){b=m.isFunction(b)?b():null==b?"":b,d[d.l...

Chrome Error:

Uncaught TypeError: Illegal invocation jquery-latest.min.js:4e jquery-latest.min.js:4Vc jquery-latest.min.js:4Vc jquery-latest.min.js:4Vc jquery-latest.min.js:4Vc jquery-latest.min.js:4Vc jquery-latest.min.js:4Vc jquery-latest.min.js:4m.param jquery-latest.min.js:4m.extend.ajax jquery-latest.min.js:4loadData (index):112m.event.dispatch jquery-latest.min.js:3r.handle 

Opera Error:

Uncaught RangeError: Maximum call stack size exceeded

every time i search, the error counter is increasing with same error message

IE 11 Error:

Argument not optional
  • 写回答

1条回答 默认 最新

  • csdnceshi62 2014-09-05 06:15
    关注

    I did not try recreating this issue just a hunch.

    typeof parseInt(page) == "number"
    

    The above statement is always true. If page is event-object the parseInt of page is NaN which will return true for the above statement.

    I think the following will be better

    $("#finder").blur(function(e) {
       executeFunction(1);
    });
    

    Other things.

    You are binding one instance of following ajaxCompleteEvent every time an ajax request complete. In other words the result is being written to the page multiple times.

          $(document).ajaxComplete(function(event, request, settings){
                $("#container").html(msg);
          });
    

    Why don't you simply use

    $("#container").html(msg);
    

    in its place?

    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面