例子:
test.html
頁面引用<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
內容有:
<div id="divMsg">Hello World!</div>
用法1:(頁面載入時讀取遠程頁面內容到divMsg)
$("#divMsg").load(http://localhost:8012/t.php, { "resultType": "html" });
返回類型resultType有如下幾種:
"xml", "html", "script", "json", "jsonp", "text"
用法2:(點擊post數據返回數據)
{
$("#divMsg").html(data);
}
);
}
</script>
post方法如下:
$.post(access_url,{
first: "test1", second: "test2"
}, function(data){
if(data.success){
$('#' + tipE).html('處理成功');
}else{
$('#' + tipE).html(data.msg);
}
},'json'
)
}
這個函數中data值為服務端返回的值,且為JSON格式,當然了,這里可以用其他類型,如text,xml等等之類。
服務端返回值是JSON格式,如:{success:true, msg:"測試成功"}
新聞熱點
疑難解答