Reputation: 11912
I have a jQuery.ajax call on a button click event in my webpage. This ajax call sends quite a lot of markup back to the server. After some processing the server posts back a small URL address. This works fine sometimes but other times doesn't. I have a breakpoint just before the ajax call and also have some in my WebMethod. It appears that sometimes the WebMethod doesn't even get hit.
What could be causing the .ajax call to fail? I'm assuming there must be something in the parameters I am sending. But I am escape
ing the markup.
Anyone got any ideas?
$.ajax({
type: 'POST',
url: 'WebServices.asmx/GetBitmapPathForVML',
contentType: 'application/json; charset=utf-8',
data: '{"sVML" : "' + escape($('#divChart')[0].innerHTML) +
'","width" : 800,"height": 600}',
dataType: 'json',
success: function(result) {
var newWindow = window.open ("", "Chart","");
//blah blah
newWindow.document.write("<BODY>");
newWindow.document.write(
'<img src="file" alt="Chart"></img>'.replace('file',result.d)
);
newWindow.document.write("</BODY>");
//blah blah
}
});
Upvotes: 1
Views: 1845
Reputation: 11912
Don't like answering my own question (not that I am, really). But the issue was to do with the maximum JSON length property.
I found the answer here
..and added this to my webconfig...
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2097152"/>
</webServices>
</scripting>
</system.web.extensions>
Thanks for all the answers guys, especially those about catching the errors.
Upvotes: 1
Reputation: 504
El Ronnoco,
I would suggest you to add a error: callback to check what is going on. Maybe you can get usefull information from that.
Upvotes: 1
Reputation: 1039248
I would recommend you rewriting your method like this:
$.ajax({
type: 'POST',
url: 'WebServices.asmx/GetBitmapPathForVML',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
sVML: $('#divChart').html(),
width: 800,
height: 600
}),
dataType: 'json',
success: function(result) {
var newWindow = window.open ("", "Chart","");
//blah blah
newWindow.document.write("<BODY>");
newWindow.document.write(
'<img src="file" alt="Chart"></img>'.replace('file',result.d)
);
newWindow.document.write("</BODY>");
//blah blah
}
});
Upvotes: 2