Asp.net Webmethod Jquery Internal Server Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack jquery ajax webmethod 500 internal server error Overflow the company Business Learn more about hiring developers or posting ads with us jquery ajax webservice internal server error Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community
500 Internal Server Error When Calling Webservice With Jquery
of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ASP.NET 500 Internal Server Error while calling webmethod from javascript up vote 0 down vote favorite
Webmethod 500 Internal Server Error
2 I'm trying to call the webmethod fucntionality using AJAX but unable to get the appropriate results. I have googled my problem and found many solution but those didn't worked for me. Please guide me what I'm doing wrong. Help will be appreciated. Cheers Code Snippet function checkUserNameExists() { //initialization var pagePath = window.location.pathname + "/getUsername"; var value = document.getElementById('control_userName').value; var dataString = "{ 'value':'" + value + "' }"; $.ajax({ type: jquery ajax post 500 internal server error asp net "GET", url: pagePath, data: dataString, contentType: "application/json; charset=utf-8", dataType: "json", error: function (XMLHttpRequest, textStatus, errorThrown) { }, success: function (result) { var flag = true; if (result != null) { flag = result.d; if (flag == "True") { alert('okay fine you are good'); } else { alert('try again'); } } } }); } Method in Behind Code file [WebMethod] [ScriptMethod(UseHttpGet = true)] public string getUsername(string value) { return "True"; } EXCEPTION ExceptionType: "System.InvalidOperationException" Message: "An attempt was made to call the method 'getUsername' using a POST request, which is not allowed." javascript c# asp.net ajax share|improve this question edited May 3 '15 at 10:09 asked May 3 '15 at 8:59 Muneeb Amjad 285211 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote accepted First, it the webmethod is in the page class, and not in a Webservice class, then it should be static. Second, the data transfered is not really a string, but an object, so change it to: var dataString = { 'value': value }; Third thing, "type" is for older versions of jquery, you should either change your ajax call to: method: "GET", url: pagePath, data: dataString, contentType: "application/json; charset=utf-8", dataType: "json",... Or change the function in the server side to get post calls,
here for a quick overview of the site Help Center Detailed
500 Internal Server Error Ajax Asp Net
answers to any questions you might have Meta Discuss the ajax post 500 internal server error c# workings and policies of this site About Us Learn more about Stack Overflow the company 500 internal server error web service call Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the http://stackoverflow.com/questions/30011998/asp-net-500-internal-server-error-while-calling-webmethod-from-javascript Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up jQuery: Ajax call to asp.net webservice fails, server return 500 error up vote 3 down vote favorite Ok, so I created a http://stackoverflow.com/questions/2027960/jquery-ajax-call-to-asp-net-webservice-fails-server-return-500-error test project just to verify that jQuery AJAX works with asp.net service, and it does no problems. I used a default HelloWorld service created in VS studio. I am calling the service via jQuery like this: in Default.aspx: in TestService.asmx using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebServiceTestWitJQuery { ///
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more http://stackoverflow.com/questions/13906316/jquery-ajax-returns-internal-server-error about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Jquery $.ajax returns internal server error up vote 1 down vote favorite internal server I am sure i am doing something bad here, but i cannot figure out what. Any advises please? And here is the debug info gathered UPDATE: By changing internal server error to data: "{var1:'test'}", and dataType: "json", everything works as expected jquery asp.net ajax share|improve this question edited Dec 16 '12 at 23:23 asked Dec 16 '12 at 22:59 OrElse 2,0842186183 5 I hope if you got a 500 response from the server it was not because anything was wrong with your client jQuery code! A 500 error is supposed to mean the fault is at the server. If that server predictably gives a 500 due to a request then it needs to be fixed. –Ray Toal Dec 16 '12 at 23:03 @RayToal nope! i do not get a 500 error. And The web method SaveValue is not called at all –OrElse Dec 16 '12 at 23:05 1 If you don't get a 500 error, then why is internal server error in the title? FYI: "internal server error" => 500 –Sparky Dec 16 '12 at 23:06 @Sparky I meant i do not get a server side 500 error. The webpage continues to operate normally. The error is raised client side... I guess :) –OrElse Dec 16 '12 at 23:09 3 I see that, but I still maintain that if you have a malformed HTTP request, say your Content-Type header w