jorgechess
jorgechess

Reputation: 1

jquery asp.net webservice call not working

I'm trying to call a webservice and always get an error, the alert error shows 'undefined'

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

this is the script

$.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);
    }
});

Upvotes: 0

Views: 839

Answers (2)

Paul Alan Taylor
Paul Alan Taylor

Reputation: 10680

Does the top of your .asmx.cs file have the following attributes, Jorge?

    /// <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

Upvotes: 0

John Koerner
John Koerner

Reputation: 38087

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.

Upvotes: 1

Related Questions