這是我在index.js代碼:AJAX不工作
$.ajax({
type: 'GET',
data: {registrationdata: registrationDataJson},
async: false,
url: 'https://example.com/push_reg',
success: function(data){
alert("Your device has been successfully registered for push notifications with device id of: " + data);
},
error: function(){
alert('There was an error registering your device');
}
});
我已經嘗試過與兩個異步的和異步關閉。我沒有從成功或錯誤中得到任何警報。我把日誌行放在/push_reg
的路線上。如果我在桌面瀏覽器中打開它,它會記錄,但不會從應用程序中記錄。在此代碼塊之前我有alert(registrationDataJson);
(registrationDataJson
是一個字符串化的JSON),所以我知道數據是好的。我在這個代碼塊之後直接輸入了alert('after');
,我從未打過,因此我知道它永遠不會超過這個塊。
它應該是'success'不'done' – Derek
您應該對「沒有詳細說明加工。」失敗功能是否正在啓動?控制檯中是否有錯誤?您是否在網絡標籤中收到錯誤代碼?代碼之前代碼是否被代碼阻塞了?另外,不要將async設置爲false。在JavaScript中不是一個好習慣。 –
@MaxBaldwin - 編輯問題。 –