Note that there are some explanatory texts on larger screens.

plurals
  1. POFrustrated with Json Response
    primarykey
    data
    text
    <p>So here is my problem. I'm using Jquery's $.ajax to pass back a series of values to a web method. The web method takes the values, creates an object and then sends it back as json to the calling page. Once I get the response back I am unable to access the response and display it's values.</p> <p>Can anyone explain what I need to do to make this work? </p> <p>The jquery script:</p> <pre><code>$(document).ready(function() { $("#create").click(function() { var name = $('#name').val(); var company = $('#company').val(); var location = $('#location').val(); var phonenumber = $('#phonenumber').val(); var country = $('#country').val(); $.ajax({ type: "POST", url: "WebService.asmx/MakeEmployee", data: "{name:'" + name + "',company:'" + company + "',location:'" + location + "',phonenumber:'" + phonenumber + "',country:'" + country + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { AjaxSucceeded(msg.d); } }); }); function AjaxSucceeded(data) { //var item = jQuery.parseJSON(data) // this doesn't work for me. $("#response").html( "&lt;ul&gt;&lt;li&gt; " + data.Name + "&lt;/li&gt;&lt;li&gt; " + data.Company + "&lt;/li&gt;&lt;li&gt; " + data.Address + "&lt;/li&gt;&lt;li&gt; " + data.Phone + "&lt;/li&gt;&lt;li&gt; " + data.Country + "&lt;/ul&gt; " ); }; }); </code></pre> <p>The web method:</p> <pre><code>[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string MakeEmployee(string name, string company, string location, string phoneNumber, string country) { Employee e = new Employee(name, company, location, phoneNumber, country); return new JavaScriptSerializer().Serialize(e); } </code></pre> <p>And the response that I'm getting back: </p> <pre><code>{"d":"\"Name\":\"bob\", \"Company\":\"google\", \"Address\":\"home\", \"Phone\":\"123\", \"Country\":\"usa\"}"} </code></pre> <p>This is what I think I should be getting back:</p> <pre><code>{"Name":"bob", "Company":"google", "Address":"home", "Phone":"123", "Country":"usa"} </code></pre> <p>The error I get once the pages renders again is this:</p> <pre><code>•undefined •undefined •undefined •undefined •undefined </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.
 

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