Jquery Ajax Webmethod 500 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 jquery ajax post 500 internal server error asp net this site About Us Learn more about Stack Overflow the company Business 500 internal server error ajax asp net Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask ajax post 500 internal server error c# Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign 500 internal server error web service call up ASP.NET 500 Internal Server Error while calling webmethod from javascript up vote 0 down vote favorite 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
Unknown Web Method
function checkUserNameExists() { //initialization var pagePath = window.location.pathname + "/getUsername"; var value = document.getElementById('control_userName').value; var dataString = "{ 'value':'" + value + "' }"; $.ajax({ type: "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
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
Unknown Web Method . Parameter Name: Methodname
the workings and policies of this site About Us Learn more webmethod c# about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack failed to load resource: the server responded with a status of 500 (internal server error) Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping http://stackoverflow.com/questions/30011998/asp-net-500-internal-server-error-while-calling-webmethod-from-javascript each other. Join them; it only takes a minute: Sign up Getting a internal server error when using Jquery ajax post method up vote 0 down vote favorite I have the following javascript code for an autoselect dropdownlist with multiselect checkbox: function f() { var data; $("#csrch").attr('value', ''); $.ajax ({ //calling aspx web method url: 'drpCtrl.aspx/CustomerFilter', type: 'POST', http://stackoverflow.com/questions/21432573/getting-a-internal-server-error-when-using-jquery-ajax-post-method //since webmethod does not have parameter given data as empty data: '', datatype: 'json', contentType: 'application/json', mimeType: 'application/json', error: function (jqxhr, status, error) { alert(error) } }); } Which is calling this web method from the code behind page [WebMethod] public string CustomerFilter() { string result = ""; //retrieving customer list from database where it returns as json format result = Convert.ToString(objSLA.ExecuteScalar (CommandType.StoredProcedure, "Usp_Get_Customer_Test")); //returning string format return result; } Webmethod CustomerFilter() is not calling and I am getting the Internal Server Error..Please help what is wrong in above said coding result: { "uin":{ "customer":[ { "i":"1", "n":"Ahold Financial Services" }, { "i":"2", "n":"ALM" }, { "i":"3", "n":"Associated Global Systems, Inc." } ] } } jquery json share|improve this question edited Jan 29 '14 at 16:37 jcolebrand 13.4k65396 asked Jan 29 '14 at 13:30 user3248877 12 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote try adding the static at you Codebehind Method: [WebMethod] public static string CustomerFilter() { string result = ""; //retrieving customer lis
Handle single quote in Javascript Please down load the project This is the error due to single quote in https://sibasisjena.wordpress.com/2014/02/26/500-internal-server-error-while-calling-webmethod-from-javascript/ your input parameter I am going to explain this issue with an example: there are two input fields in my page 1. Name 2. State Case1 : put any value except single quote in both the fields and submit. it will work fine. Case2 : put single quote in name field and in state field put internal server any value. Open firebug console and check result:500 Internal Server Error Problem : The single quote is creating problem. Solution:Replace all the single quote in the value with a ♣ and in webmethod again replace all the ♣ with single quote. login.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="CallAjaxWebmethod.login" %>