为什么JQuery的AJAX调用不工作? [英] Why JQuery AJAX call is not working?

查看:318
本文介绍了为什么JQuery的AJAX调用不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的JQuery AJAX方法:

The following is my JQuery AJAX method:

function meFun() {
    alert('enter');

    $.ajax({
        type: "POST",
        url: "About.aspx/GetRes",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            // Do something interesting here.
            alert(msg);
        }
    });
    alert('end');

}

以下是我的按钮code:

The following is my button code:

<input type="button" onclick="meFun();" value="Click me" id="btn" />

Folling是我在About.aspx功能

Folling is my function in About.aspx

Public Function GetRes() As Boolean
    Return True
End Function

meFun()方法调用成功,但不叫 GetRes()和AJAX调用不返回任何响应。

The meFun() method is called successfully but doesn't call the GetRes() and the AJAX call doesn't return any response.

任何想法,为什么?另外,请提出来调试这些类型的问题,AJAX的一个很好的方式。

Any idea why? Also, please suggest a good way to debug these sorts of AJAX problems.

推荐答案

首先,确保你有你的服务器端GetRes功能WebMethod属性(这是在C#中,我不知道你是怎么做的,在VB)并GetRes静态的(或者任何在VB中相当于是)。

First, make sure you have the WebMethod attribute on your server side GetRes function (this is in C#, I don't know how you do that in VB) and make GetRes static (or whatever the equivalent in VB is).

[WebMethod]
public static bool GetRes()
{
  return true;
}

然后,添加错误处理您的jQuery AJAX 电话:

Then, add the error handlers to your jQuery ajax call:

$.ajax({
        type: "POST",
        url: "About.aspx/GetRes",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            // Do something interesting here.
            alert(msg);
        },
        error: function (data) {
        }
    });
    alert('end');

编辑:调试,设置错误处理程序设置断点,检查数据参数。所有的浏览器(好吧,我可以保证IE,火狐(使用Firebug)和Chrome)具有良好的脚本调试。如果发生错误,将有数据属性,其中逃避我此刻的名称,详细解释了该错误。

to debug, set a breakpoint in the error handler and inspect the data parameter. All browsers (well, I can vouch for IE, Firefox (with Firebug) and Chrome) have good script debuggers. If an error occurs, there will be a property in data, the name of which eludes me at the moment, that explains the error in detail.

这篇关于为什么JQuery的AJAX调用不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆