sách gpt4 ai đã đi

Javascript AJAX 调用 Jquery 调用

In lại 作者:行者123 更新时间:2023-12-02 19:27:48 30 4
mua khóa gpt4 Nike

为了让我的代码几乎完全用 Jquery 编写,我想用 Jquery 重写 AJAX 调用。

这是从网页到 Tomcat servlet 的调用。

我目前情况的类似代码:

var http = new XMLhttpRequest();
var url = "http://example.com/MessageController?action=send";

http.onreadystatechange = function ()
if (http.readyState == 4)
{
if (http.status == 200){ var response = http.responseText;}
else {/*code2*/}
};
http.async = false;
http.open("POST", url, true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.send(string);

哪种方法是做到这一点的最佳方法? .ajax 还是 .post?你能帮我一些伪代码来启动这个吗?

1 Câu trả lời

sử dụng.ajax或(当您使用 POST 时).post :

$.ajax({
url: "http://example.com/MessageController",
loại: "POST",
data: { action: "send", yourStringName: "something" },
async: false, // make sure you really need it
contentType:'application/x-www-form-urlencoded'
}).done(function(response) {
console.log(response);
});

使用哪一个并不重要,因为 .post Đúng .ajax 的简写。

关于Javascript AJAX 调用 Jquery 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11849251/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com