如何在JSON中设置async:false

时间:2014-08-27 13:29:48

标签: javascript json html5

请帮助我如何在此代码中输入async:false

$.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 个答案:

答案 0 :(得分: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
});