0

我正在尝试调用 Web 服务,但总是出现错误,警报错误显示“未定义”

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string Test()
{            
    JavaScriptSerializer js = new JavaScriptSerializer(); 
    return js.Serialize("Hello");
}

这是脚本

$.ajax({ type: "POST",

    contenttype: "application/json; charset=utf-8",
    data: "{}",
    url: "WorkflowAjaxHelper.asmx/Test",
    dataType: "json",
    async: false,

    success: function (res) {
        alert('success');
    },

    error: function (err) {
        alert(err.text);
    }
});
4

2 回答 2

1

Text is not valid on the error object. You could use, any of the following, to get more info:

responseText 
status 
statusText

Leverage the debuggers built into Chrome, IE, or Firefox to help debug. You can also console.log an object and chrome and firefox are nice enough to let you click through the object model to see what is available.

于 2012-07-19T14:27:52.177 回答
0

Jorge,您的 .asmx.cs 文件的顶部是否具有以下属性?

    /// <summary>
    /// Summary description for PartServices
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 

    // This bit here!!!

    [System.Web.Script.Services.ScriptService]
    public class PartServices : System.Web.Services.WebService
于 2012-07-19T14:34:54.517 回答