[英]converting XMLHTTPRequest To jquery ajax
I try lots of ways to convert my XMLHTTPRequest into jQuery ajax but I couldn't be successful.我尝试了很多方法将我的 XMLHTTPRequest 转换为 jQuery ajax,但我无法成功。
I would be really appreciate if anyone could help me solve this issue.如果有人能帮助我解决这个问题,我将不胜感激。
here is my XMLHttpRequest Code:这是我的 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);
and here is my attempt but its not working这是我的尝试,但它不起作用
$.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); }
});
Try this尝试这个
$.ajax({
url: "<?php echo $this->ui_url('onlineexamcats', 'all'); ?>",
data: "ajax=1",
type: "POST",
processData: false,
success: function(res) { console.log(res); }
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.