需要帮助将AJAX代码转换为jQuery [英] Need help converting AJAX code to jQuery
本文介绍了需要帮助将AJAX代码转换为jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我将下面的代码转换为jQuery吗?
Can someone please help me convert the code below to jQuery?
var xmlhttp;
if (window.XMLHttpRequest)
{
// Code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{
// Code for IE5, IE6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "http://www.my.com", true);
xmlhttp.setRequestHeader("MyHeader", "hello");
xmlhttp.send();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
document.getElementById("responseText").innerHTML = xmlhttp.responseText;
}
}
}
推荐答案
简单示例...
$.ajax({
"type": "get", // optional
"url": "http://www.my.com",
"headers": { "MyHeader": "hello" },
"success": function (data) {
document.getElementById("responseText").innerHTML = data;
}
});
有关更多选项,请参见文档.
See documentation for more options.
这篇关于需要帮助将AJAX代码转换为jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文