javascript - How to call JSON methods from C# WebService from external server -


How can I use the HTML5 / JavaScript site in an ASP.NET Web service (C #)? And the Web service is not in the same site as the client, so it will be a cross-domain request.

I have a little bit of experience in web programming, and all my ASP.NET pages have a faster interface For taking HTML 5 and JS, I tried to connect to my Web service for JSSR, it was a real struggle, JSON was the answer, and information

First / Server Side < / Strong>

mywebservice.asmx

will be hosted in the next web service site, Site.com

Then address "Site.com/MYWS.asmx/JSONMethod" "[WebServices (namespace =" http: // ... ")] [System.Web.Script.Services.ScriptService] Public class MYWS {[WebMethod] [ScriptMethod (UseHttpGet = true, response format = response.jason)] Public string JSONMethod (/ * Paratip Parnanam, Paratip Parnassem 2, .. etc * /) {List & lt; Object & gt; Tempobjects = New list & lt; Object & gt; (); Tempobjects.Add (New {ID = ID, Val = Val / * More Params => ParName = "ParValue", etc. *)} Var retVal = New JavaScriptSerializer () Serialize (tempobjects.ToArray ()); Reference. Response Contact Type = "App / Jason"; Var p = ""; If (Referrer Request.Palm.AllKeys.Contains ("callback") == true) P = references. request. Mercury ["callback"]. ToString (); Reference. response. White (String.format (Culture Info. Invent Culture, "{0} ({1})", P, Rate Val)); }}

Second / Customer side

myJS.js

function myJSMethod () {$ .ajax ({url: "site.com/MYWS.asmx/JSONMethod", data: {ParName: "parValue" / *, ParName2 ... etc * / }, Type: "GET", data type: "jsonp" // if the method}) .done (function) {// What you need to get from the JSN data ... ... here Code ... / / If you are being used by any other JS, then you need to call the method when using // window ["jsmpath"] (data) //; if received jsn Juru File (function (jquxhr, textstatus, altitudetown) {warning (jqXHR); warning (textstats); warning (error trova);})}}

hope This works for you because it works for me Good luck and happy coding.

- Poncho


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -