ajax的三种方式请求

来源:互联网 发布:淘宝售假仅退款不退货 编辑:程序博客网 时间:2024/05/23 17:25
第一种

/* $.post("http://localhost:8080/webme/category_danceAll.action", {
dance:$("#searchtext").val()

},function(data) {
  if(data!=null){
   alert(data);
  }
 

},"text");



};

第二种

$.ajax({
             type: "GET",
             url: "http://localhost:8080/webme/category_danceAll.action",
             data: {dance:$("#searchtext").val()},
             dataType: "text",
             success: function(data){
                        alert(data);
                      }

         });

第三种

/* 创建异步对象 */
function createXmlHttp() {
var xmlHttp;
try { // Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
try {// Internet Explorer
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
}


return xmlHttp;
}
/* 搜索框  ajax请求*/
function search() {
var xhr = createXmlHttp();

// 3.打开连接
xhr.open("GET",
"http://localhost:8080/webme/category_danceAll.action?time="
+ new Date().getTime() + "&dance="
+ $("#searchtext").val(), true);
// 4.发送
xhr.send(null);
// 2.设置监听
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {

alert(xhr.responseText);

}
}
}


}
         }; */
原创粉丝点击