我嘗試了很多方法將我的 XMLHTTPRequest 轉換為 jQuery ajax,但我無法成功。
如果有人能幫我解決這個問題,我將不勝感激。
這是我的 XMLHttpRequest 代碼:
var url = url;
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}};
var data = "ajax=1";
xhr.send(data);
這是我的嘗試,但它不起作用
$.ajax({
url: "<?php echo $this->ui_url('onlineexamcats', 'all'); ?>",
data: JSON.stringify("ajax=1"),
type: "POST",
processData: false,
contentType: false,
beforeSend: function(xhr){xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");},
success: function(res) { console.log(res); }
});
uj5u.com熱心網友回復:
試試這個
$.ajax({
url: "<?php echo $this->ui_url('onlineexamcats', 'all'); ?>",
data: "ajax=1",
type: "POST",
processData: false,
success: function(res) { console.log(res); }
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/478132.html
