using jquery ajax to load info from database

后端 未结 3 1282

Problem

I tried using the following

// Start method 1

var grbData = $.ajax({
        type : \"GET\",
        url : \"http://grb.sonoma.edu:81/getg         


        
3条回答
  •  醉话见心
    2020-12-20 03:19

    If you want to use the first one, you should pass in a async:false.

    var grbData = $.ajax({
        type : "GET",
        url : "http://grb.sonoma.edu:81/getgrbs.php",
        async: false,
        data : "start=0&perPage=3"}).responseText;
    

    The $.ajax call is asychronous so the $.ajax call will give you that message you saw about data not being ready. This of course kind of defeats the purpose of AJAX since user interaction is blocked.

    A better method might be:

    var grbData = $.ajax({
        type : "GET",
        url : "http://grb.sonoma.edu:81/getgrbs.php",
        dataType: 'html',  // assuming your service returns HTML
        success: function(data) {
          $("#ajaxDiv").html(data);
        }
     });
    

提交回复
热议问题