Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is what I tried and it worked perfectly:</p> <p>Client:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function () { $('#testbutton').click(function () { $.ajax({ type: "POST", url: "WebService1.asmx/HelloWorld", cache: false, contentType: "application/json; charset=utf-8", data: "{}", dataType: "json", success: function (data, status) { var response = $.parseJSON(data.d); alert(response.message); alert(status); }, error: function (xmlRequest) { alert(xmlRequest.status + ' \n\r ' + xmlRequest.statusText + '\n\r' + xmlRequest.responseText); } }); }); }); &lt;/script&gt; </code></pre> <p>Serverside Webservice Call:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebApplication2 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "{ \"message\":\"Hello World\" }"; } } } </code></pre> <p>Make sure you have <code>[System.Web.Script.Services.ScriptService]</code> attribute on your webservice class. </p> <p>NOTE: in the example above the returned JSON is hardcoded, but you can just as easily serialize the objects you want to return as JSON as follows for a hypothetical person object:</p> <pre><code>Person p = new Person(); p.FirstName = "Bob"; p.LastName = "Smith"; p.Age = 33; p.Married = true; Microsoft.Web.Script.Serialization.JavaScriptSerializer jss = new Microsoft.Web.Script.Serialization.JavaScriptSerializer(); string serializedPerson = jss.Serialize(p); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload