javascript
  • json
  • html5
  • 2014-08-27 23 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

    相關問題