2013-10-14 28 views
0

我試圖讓救援人員到場AJAX的登錄狀態,但AJAX查詢是沒有發生正常。jQuery的Ajax錯誤 - 無法捕獲錯誤

function getdetails(playlistname) { 
alert(playlistname); 
$.ajax({ 
    type: "POST", 
    url: "model/login_details1.php", 
    beforeSend: function (xhr) { 
     alert("before send"); 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     alert("ajax error - arun"); 
     alert(xhr.status); 
     alert(thrownError); 
    }, 
    data: { 
     fname: name, 
     playlistname: playlistname 
    } 
}).done(function (result) { 

    if (!sessionStorage['pid']) { 
     sessionStorage['pid'] = result; 

    } // window.location = "Playlist.html"; 
}); 
} 

我在發佈之前收到警報,但發佈(錯誤)後的警報正在消失。

+1

爲什麼不把所有東西都放成.done,.fail,.always,看看會發生什麼? – TimSPQR

+0

首先我開始做起來難。它沒有給出任何有意義的答覆。在另一篇文章中,我看到它與相同的原產地政策有關。有沒有人告訴這也未嘗如何處理同根同源的政策。在我的情況下,其相同的域 – reach2arunprakash

+0

只是覆蓋顯而易見的,但你的要求,甚至導致開始與一個錯誤?什麼是例如Firebug告訴你?除了@TimSPQR所說的內容之外,你還可以用'alert()'或'console.log()'代碼分配'complete:'和'success:'事件處理程序。附註:格式化代碼可以幫助我們爲能夠快速和相關反饋。 ] – WynandB

回答

0

嘗試AJAX以下格式,可以幫助你很快找出錯誤。

function getdetails(playlistname) { 
    alert(playlistname); 
    var name = "" //here is your value. 
    $.ajax({ 
     type: "POST", 
     url: "model/login_details1.php", 
     data: { 
      fname: name, 
      playlistname: playlistname 
     }, 
     beforeSend: function (xhr) { 
      alert("before send"); 
     }, 
     success: function (result) { 
      console.log(result); //use this to see the response from serverside 
      if (!sessionStorage['pid']) { 
       sessionStorage['pid'] = result; 
      } 
      // window.location = "Playlist.html"; 
     }, 
     error: function (xhr, ajaxOptions, thrownError) { 
      alert("ajax error - arun"); 
      alert(xhr.status); 
      alert(thrownError); 
     } 
    }); 
} 
相關問題