1、asp.net項目,前台使用ajax向後台傳值,怎麼能確定有沒有呼叫到後台的方法呢?設斷點根本走,然後回傳結果也看不出什麼問題就是直接回應error方法了。求指教!
頁:
# 後台:
#瀏覽器:
#response:
##
PHP中文网2017-05-19 10:19:24
你發送ajax請求時,指定要接收的資料類型為 json
而你后端返回的数据不是json
個格式。所以認定為請求失敗,進入失敗回呼。
而且你後端寫的有問題吧。瀏覽器的response是一個HTML頁面?
這些地方應該是response.write('xxxx')
吧
然後response.end()
吧
後端回應資料不都應該是response.write
嗎?
補充:
肯定寫錯了吧
html
<pre id="test">
</pre>
<pre id="test2">
</pre>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$.ajax({
url: "./test.aspx",
dataType: 'json'
}).done(function (data) {
// 指定为类型为json 则会将数据处理为对象的 即自动JSON.parse 了
$('#test').text('data类型' + typeof data + '\n' + JSON.stringify(data, null, 4));
}).fail(function () {
alert('fail');
});
$.ajax({
url: "./test.aspx"
}).done(function (data) {
alert('data类型' + typeof data + '\n');
$('#test2').text('data类型' + typeof data + '\n' + data);
}).fail(function () {
alert('fail');
});
</script>
test.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
String str = @"[{
""guid"": ""410000197812057474"",
""name"": ""当进少头等程给进话团拉组层育除水"",
""url"": ""mailto://cixus.vg/wvgermuy"",
""date"": ""03-25"",
""status"": """",
""openType"": ""tabsnav""
}, {
""guid"": ""42000020111028506X"",
""name"": ""张度联酸做电往"",
""url"": ""mailto://pslic.sa/mhsgmxqur"",
""date"": ""08-08"",
""status"": """",
""openType"": ""dialog""
}, {
""guid"": ""520000199308053591"",
""name"": ""政劳则加派党王存才从她"",
""url"": ""telnet://lvgoxn.iq/imsfzmfjk"",
""date"": ""06-06"",
""status"": """",
""openType"": ""dialog""
}]";
Response.Write(str);
Response.End();
}