Inside my ASP.NET website I am calling a Web Method using Jquery as follows:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{'param1': '" + param1 + "','param2': '" + param2+ "' }",
dataType: 'json',
url: "Default.aspx/TestMethod",
error: function (jqXHR, textStatus, errorThrown) {
alert("error: " + textStatus);
},
success: function (msg) {
document.getElementById("content").innerHTML = msg.d;
}
});
Web Method Definition is:
[System.Web.Services.WebMethod]
public static String TestMethod(String param1, String param2)
{
String to_return = /* result of operations on param1 and param2 */;
return to_return;
}
My result is a String containing HTML code.
It is working perfect if the to_return
string is small.
But it is giving me error as:
500 Internal Server Error 6.22s
I tried to explore it using FireBug in Response it shows me:
{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}
Using breakpoints in Visual Studio, I have copied the to_return
string into a text file. Size of the file became: 127 KB.
What possibly went wrong?
data: "{'param1': '" + param1 + "','param2': '" + param2+ "' }"
? You can declare an actual JavaScript object, you don't have to make it a string that represents the object. – Meyerhoferror
callback function to doconsole.log(errorThrown);
then use your browser's developer tools to see what's logged in the console; it might give you a clearer idea of what the error is. Also check that theto_return
string represents valid JSON in the request that's failing; jQuery will error if it can't parse the response as JSON when you specifydataType: 'json'
. – Meyerhof