一個ajax的Post請求,ajaxPost請求
<1>
//一個ajax的Post請求 function submitInfo() { $(".warn").hide(); //剛提交的時候隱藏錯誤的資訊 var data = $("#formData").serialize(); //將表單的資料通過序列化表單值,建立 URL 編碼文本字串。形成一個表單元素集合的 jQuery 對象 $.post("/login/checkLoginInfo", data, function (ajaxObj) { //將資料提交到login控制器下的CheckLOginInfo方法。參數是data。 如果請求成功,function就是請求成功時執行的回呼函數。ajaxObj是checkLoginInfo方法的返回資料 //回傳內容{status: 1(success)/0(fail),} if (ajaxObj.status == 0 || status == null) { //如果返回狀態為0或者為null $(".warn").show(); //將錯誤資訊顯示出來 } else { //登陸成功,跳轉都制定頁面 window.location = '/HotelList/Index'; } }, "json"); }
為何用ajax向同一個頁面發送post與get,post伺服器端的代碼不執行,而換成get時就一切正常?
.net會在頁面的表單中隱藏一些hidden框的,傳遞一些資訊的。
你直接ajax提交的話,這些資訊都沒有提交,所以後台狀態不對。
把IsCallback的判斷去掉吧,自己傳遞一些參數作為標誌位,進行判斷。
一個jquery ajax post asp的例子
<script type="text" src="jquery.js"></script>
<script>
$.post("1.asp", { id:1, t:Math.random()},
function(data){
if(data=="success")
{
alert('操作成功');
}
else{
alert('操作失敗,請重試');
}
});
</script>
1.asp中的內容是<% response.write "success" %> 或者是<% response.write "error" %>