Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm making a simple call to a Webmethod (Pagemethod), but I keep getting this error:

[object XMLHttpRequest]

Javascript:

                var id = $('#' + this.Div).attr('id');
                var test = $('#' + id).parent('.Prod-top-time').prev().attr('id');
                test = test.replace('navn_', '');

                var parameters = {'auktionid': test};

                $.ajax({
                type: "POST", 
                url: "Default.aspx/AuctionEnd", 
                data: JSON.stringify(parameters),                   
                //data: JSON.stringify({ auktionid: 34}),  
                contentType: "application/json; charset=utf-8", 
                dataType: "json", 
                error: function(ret) 
                {
                    if (ret.hasOwnProperty('d'))
                      stuff(ret.d);
                    else
                      stuff(ret);
                       }
                       });

                function stuff(msg) {
                              alert(msg);
                             }

In the first part, I extract a value from a div id. This is a number used as parameter.

The Webmethod is as simple as this: (Just for testing so far)

[WebMethod]
public static string AuctionEnd(int auktionid)
{
    return auktionid.ToString();

}

No matter what I throw at it, it returnes that error.

share|improve this question
    
You will probably get alot of information if you check the server response in the console or net tab i firebug. –  Oscar Apr 8 '11 at 12:30

2 Answers 2

i could find a light at the end of the tunnel when you want use WebMethod in jquery , you must add this tag to web.config

<configuration>
  <system.web>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
  </system.web>
</configuration>

good luck

share|improve this answer

You are showing the error object in the message box. The error function returns as follows:

error(jqXHR, textStatus, errorThrown)Function 

A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". This is an Ajax Event. As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests.

you need to show the details of the jqXHR object.

The jqXHR Object

The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible.

All information is at

http://api.jquery.com/jQuery.ajax/

And example ajax call i use with error handler is:

        //Call the approve method on the code behind
        $.ajax({
            type: "POST",
            url: ResolveUrl("~/Pages/Mobile/Login.aspx/LoginUser"),
            data: "{'Username':'" + $Username + "', 'Password':'" + $Password + "' }", //Pass the parameter names and values
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Error- Status: " + textStatus + " jqXHR Status: " + jqXHR.status + " jqXHR Response Text:" + jqXHR.responseText) },
            success: function (msg) {
                if (msg.d == true) {
                    window.location.href = ResolveUrl("~/Pages/Mobile/Index.aspx");
                }
                else {
                    //show error
                    alert('login failed');
                }
            }
        });

Note the difference in the error handler

Updated Example:

        //Call the approve method on the code behind
        $.ajax({
            type: "POST",
            url: "Default.aspx/AuctionEnd",
            data: "{'auktionid':'" + test+ "'}", //Pass the parameter name and value
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            error: function (jqXHR, textStatus, errorThrown) {
                alert("Error- Status: " + textStatus + " jqXHR Status: " + jqXHR.status + " jqXHR Response Text:" + jqXHR.responseText) },
            success: function (msg) {
                if (msg.d == true) {
                    alert('success');
                }
                else {
                    //show error
                    alert('failed');
                }
            }
        });
share|improve this answer
1  
The second argument passed to the error function is a text version of the error. –  Oscar Apr 8 '11 at 12:28
    
@Oscar - thanks +1 –  WraithNath Apr 8 '11 at 12:35
    
The result of this is: Error- Status: parsererror jqXHR Status: 200 –  Soeren Apr 8 '11 at 12:43
    
Sounds like malformed json data, try data: "{'auktionid':'" + test+ "' }" –  WraithNath Apr 8 '11 at 12:46
    
Same error. I must have tried every possible way to format that json data... –  Soeren Apr 8 '11 at 13:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.