var xmlhttp;
if(window.XMLHttpRequest){
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xmlhttp = new XMLHttpRequest();
}
else
// IE6, IE5 浏览器执行代码
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
document.getElementById("root").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","URL",true);
xmlhttp.send();
xmlhttp.open('post','url',true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=xiong&lname=ying");
$(document).ready(function(){
$('button').click(function(){
//ajaxSetup用来为将来的ajax请求设置默认值
$.ajaxSetup({
url:"",
data:"",
dataType:"json",
type:'get',
success:function(result,status,xhr){
document.getElementById("root").innerHTML = reuslt;
$("#div").html(result);
},
error:function(err){
alert(err);
},
contentType:"applicaton/x-www-form-urlencoded",
username:"xiongyingcai",
password:"123",
timeout:"50"
});
//写好$.ajaxSetup()设置好默认值之后,这里我们就可以直接使用$.ajax()了
$.ajax();
})
});
//$.get()方法的使用,其格式大致为:$.get(URL,data,function(data,status,xhr),dataType)
$.get(
"",//url
{ 'colors[]' : ["Red","Green","Blue"] },//传入的数据
function(data,status,xhr){//成功时的回调函数
alert("数据:"+data+"状态:"+status);
},
json//dataType 其类型大致如下
// "xml" - 一个 XML 文档
// "html" - HTML 作为纯文本
// "text" - 纯文本字符串
// "script" - 以 JavaScript 运行响应,并以纯文本返回
// "json" - 以 JSON 运行响应,并以 JavaScript 对象返回
// "jsonp" - 使用 JSONP 加载一个 JSON 块,将添加一个 "?callback=?" 到 URL 来规定回调
)
$.noConflict();
jQuery(document).ready(function(){
jQuery("button").click(function(){
jQuery("#root").text("nibushi")
})
});
//或者
var p = $.noConflict();
p(document).ready(function(){
p("button").click(function(){
p("#root").text("nibushi")
})
});