javascript
  • json
  • html5
  • 2014-08-27 21 views 0 likes 
    0

    请帮我,我怎么可以把异步:假这段代码如何设置异步:假以JSON

    $.getJSON("http://192.168.1.100:8080/m-help/apps/json_doctor.php", function(data) { 
        $.each(data.result, function(){ 
         $("#list").append("<li><a href='doctor-details.html?id=" +this['id']+ "'><span class='img'>  <img src='http://192.168.1.100:8080/m-help/images/upload/"+this['images']+"' alt=''/></span>" +this['doclname']+ ", " +this['docFname']+ "</a></li>"); 
        }); 
    }); 
    
    +1

    你为什么需要这个?上下文是什么? – Onheiron 2014-08-27 13:31:11

    +0

    您应该避免同步AJAX调用。它被称为AJAX的原因! – 2014-08-27 13:36:51

    回答

    4

    你不能。 jQuery的简写ajax函数对他们提供的定制非常有限。改为使用.ajax

    function success (data) { 
        $.each(data.result, function(){ 
         $("#list").append("<li><a href='doctor-details.html?id=" +this['id']+ "'><span class='img'>  <img src='http://192.168.1.100:8080/m-help/images/upload/"+this['images']+"' alt=''/></span>" +this['doclname']+ ", " +this['docFname']+ "</a></li>"); 
        }); 
    }); 
    
    var url = "http://192.168.1.100:8080/m-help/apps/json_doctor.php"; 
    
    $.ajax({ 
        dataType: "json", 
        url: url, 
        success: success, 
        async: false // This is horrible and will lock up the UI while it runs 
    }); 
    
    +0

    如何将该代码转换为ajax? – PPjyran 2014-08-27 13:33:57

    相关问题