网页
// in script tag
$(document).ready(function () {
var url = "list.ashx";
$.get(url + "?get", function (r1) { alert("get: " + r1); });
$.post(url + "?post", function (r2) { alert("post: " + r2); });
$.ajax(url + "?ajax", function (r3) { alert("ajax: " + r3); });
$("div:last").load(url + "?load", function (r4) { alert("load: " + r4); });
});
// in body tag
<div></div>
在“list.ashx”中
public void ProcessRequest (HttpContext context) { context.Response.Write("ok"); }
结果
- $.get 和 $.post 到达 list.ashx 但没有返回
- $.ajax 没有到达 list.ashx
- $.load 完全成功
问题是
- 为什么只有 '$.load' 有效?
- 如何使 $.get 或 $.post 工作?
更新
$("input").click(function () {
$.ajax({ url: url
, context: this
, data: "ajax=test"
, cache: false
, async: false
, global: false
, type:"POST"
, processData: false
, dataType: "html"
, success: function (data) { alert(data); }
, error: function (data) { alert(data.responseText); }
});
});
它总是命中错误:函数(){},但“data.responseText”是正确的结果!!