neuDev33 neuDev33 - 6 months ago 33
JSON Question

.ajax() post request to send JSON data to server only works in debug mode

I'm trying to add a json string to the DB, and calling a web-service in the URL of the ajax call. The string is inserted in the DB when I step through the code with the chrome debugger. However, if I don't run in debug mode, I get an error message whose response text is blank.

I know the problem is NOT with the web serbvice as it works fine independantly. Does anyone know why this may happen?

Here's some code



var object1 = { obj: 'newobj2' };

$.ajax({
type: 'POST',
url: 'saveJSON.asmx/submitToDB',
dataType: 'json',
data: object1,
success: function () { alert("success"); },
error: function (response) {
alert("error: " + response.responseText);
}
});

Answer

Probably due to caching. Try setting cache to false in the request.

   $.ajax({
        cache: false,
        type: 'POST',              
        url: 'saveJSON.asmx/submitToDB',
        dataType: 'json',
        data: object1,
        success: function () { alert("success"); },
        error: function (response) {
            alert("error: " + response.responseText);
        }
    });
Comments