解决方案 »

  1.   

    下面是jquery官网的例子,实现这个 .fail?// Assign handlers immediately after making the request,
    // and remember the jqxhr object for this request
    var jqxhr = $.getJSON( "example.json", function() {
      console.log( "success" );
    })
      .done(function() {
        console.log( "second success" );
      })
      .fail(function() {
        console.log( "error" );
      })
      .always(function() {
        console.log( "complete" );
      });
     
    // Perform other work here ...
     
    // Set another completion function for the request above
    jqxhr.complete(function() {
      console.log( "second complete" );
    });
      

  2.   


    试过了,如果没涉及到跨域的话,可以用这个方法,
    涉及到跨域就失效了
    看这里内容很多
    http://api.jquery.com/jQuery.ajax/var jqxhr = $.ajax( "example.php" )
      .done(function() {
        alert( "success" );
      })
      .fail(function() {
        alert( "error" );
      })
      .always(function() {
        alert( "complete" );
      });
     
    // Perform other work here ...
     
    // Set another completion function for the request above
    jqxhr.always(function() {
      alert( "second complete" );
    });
      

  3.   

    跨域使用JSONP
    $.getJSON('http://127.0.0.1/PGapJQM4Net/WS4JQM.asmx/GetTestList?callback=?', {
                //无参数
            }).done(function (response) {
    console.log(response.success);
                if(response.success){
                    var htmlStr = "";
                    $.each(response.data,function(i,o){
                        htmlStr += '<li><a href="http://www.baidu.com">'+o.id+' ' + o.name+'</a></li>';
                    });
                    $("#lvtest").html(htmlStr);
                    $("#lvtest").listview("refresh");
                }
            }).fail(function (jqxhr, textStatus, error) {
                console.log(error);
            });
    自动产生回调
      

  4.   


    $.getJSON('http://127.0.0.1/PGapJQM4Net/WS4JQM.asmx/GetTestList?callback=?', {
                //无参数
            }).done(function (response) {
    console.log(response.success);
                if(response.success){
                    var htmlStr = "";
                    $.each(response.data,function(i,o){
                        htmlStr += '<li><a href="http://www.baidu.com">'+o.id+' ' + o.name+'</a></li>';
                    });
                    $("#lvtest").html(htmlStr);
                    $("#lvtest").listview("refresh");
                }
            }).fail(function (jqxhr, textStatus, error) {
                console.log(error);
            });