asp.net ajax - How to call C# Rest Web service from javascript -


I created the rest architecture based web service in C # which will return a Jason string. I want to use this web service Javascript How can I call this webservice from javascript?

Use an object (or is a com-based brother):

  function getJSON () {var xhr = window.XMLHttpRequest? New XMLHttpRequest (): New ActiveXObject ('Microsoft.XMLHTTP'); Xhr.open ("GET", "http://mysite.com/myscript.asp", true); Xhr.onreadystatechange = function () {if (xhr.status == 200 & amp; amp; xhr.readystate == 4} {if (JSON) // Available by json2.js or native JSON var results = JSON.parse Browsers with (xhr.responseText); Else var result = eval ('(' + xhr.responsetext + ')'); // do something with the result here}} xhr.send (); }  

json2.js is a script for secure JSON parsing, and is available from

.

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 -