简体   繁体   中英

How to Debug ajax REST calls (in general)

I have an cURL call that works and I have converted it to an ajax call. The ajax call is failing. How do I get something to return from the call? There should be a dictionary [cURL call returns a dictionary].

How do I know what is failing in my call? I don't know how to proceed in debugging it.

Thanks

curl -v -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -X PUT --user user:pass https://my.address.for/this/url -d "{\"name\": \"Marcus0.3\",\"start\": 500000,\"end\": 1361640526000}"


                    $.ajax({
                    type: 'put',
                    url: 'https://my.address.for/this/url',
                    dataType: 'json',
                    async: false,
                    username: 'user',
                    password: 'pass',
                    data: {
                        "name": "Marcus0.3",
                        "start": 500000,
                        "end": 1361640526000
                    },
                    success: function(){alert('DONE!');},
                    error: function(){alert('fail');},
            }).responseText;

I keep getting 'fail' responses

If you type F12 it will open up chrome dev tools, then click on the network tab.

You will see all requests, including ajax requests as they happen. You can click on the line item "name" field for full info about the request and response, similar to cURL verbose mode

You can use Firefox with firebug to get the exact error message.Else do like this

error:function(error){alert(error)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM