webservice client - Calling web service using javascript error -


I try to make a webservice call using JSSN, when I call the web service without limit parameters I work for it, but when I try to send the parameter, Ive got an error:

This is my code:

  function GetSynchronousJSONResponse (url, postData ) {Var xmlhttp = null; If (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest (); Otherwise if (window.ActiveXObject) {if (new ActiveXObject ("Microsoft.XMLHTTP")) xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); Else xmlhttp = New ActiveXObject ("Msxml2.XMLHTTP"); } Url = url + "? Rnd =" + Math.random (); // ensure the non-cached version xmlhttp.open ("POST", url, false); Xmlhttp.setRequestHeader ("content-type", "app / jason; charset = utf-8"); Xmlhttp.send (POSTDATA); Var response text = xmlhttp.responseText; Return feedback lesson; } Function test () {var result = GetSynchronousJSONResponse ('http: // localhost: 1517 / Mysite / Myservice.asmx / myProc', '{"MyParam": "' + 'test' + '"}'); Result = eval ('(' + result + ')'); Warning (result.d); }  

This error is:

System. Resident Operation Exception: The request format is invalid: Application / Jason; Charset = utf-8

System on Web. Service. Protocol. Http server protot Read Parameters ()

On the system. Web services. Protocol. WebseedWandler Coreprosession Request

What's Wrong?

Thanks in advance

U can call the web service in Javascript This JSON Will return :)

  $ AJAX ({type: "post", url: ', data: JSON.stringify ({ID: 'A'}), Content Type: "Application / Jason; Charset = UTF-8", Datatype: "Jason", Process Data: Incorrect, Success: (Function (Provider List) {var obj = jQuery.parseJSON (providerlist. D); Providers (OBJ);}), Error: Function (Data) {}}); Namespace TECH_WEBRTC.Service {/// & lt; Summary & gt; Summary Details for /// Users & lt; / Summary & gt; [WebServices (Namespace = "http://tempuri.org/")] [Websisibing (conferenfo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem (false)] // Allow this web service to call scripts For example, by using ASP.NET AJAX, delete the following line [System.Web.Script.Services.ScriptService] Public class users: System.Web.Services.WebService {[WebMethod] // [ScriptMethod (ResponseFormat = ResponseFormat.Json)] // Specify return format. Public string Getprovider {string ID} {list & lt; Comman1 & gt; Obj = new list & lt; Comman1 & gt; (); JavaScriptSerializer JS = New JavaScript Serializer (); Obj.Add (new Comman1 {id = "1"}); Obj.Add (new Comman1 {id = "2"}); Obj.Add (new Comman1 {id = "2"}); //Context.Response.Write (js.Serialize (obj.ToList ())); Return js.Serialize (obj.ToList ()); }}  

}

Its work is fine :)


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -