How do I debug a jQuery Ajax request?

前端 未结 5 1731
南方客
南方客 2020-12-11 19:06

My code is:

var test = \"it isn\'t working\";
var response = $.ajax({
    type: \'GET\',
    url: \'jquerydemo.php\', //This is in the same site as the page          


        
5条回答
  •  我在风中等你
    2020-12-11 19:51

    Move that alert(test) from end into the success function of the ajax call. If it alerts it means code is working else it is not. you can only debug ajax call on its success return.

    var test = "it isn't working";
    var response = $.ajax({
        type: 'GET',
        url: 'jquerydemo.php', 
        success: function(){
                test = "it's working";
                alert(test);   //It will alert when you ajax call returns successfully.
            },
        error: function(){
                alert("Error detected");
            }
     }).responseText;
    

    Hope this helps.

提交回复
热议问题