So here is my problem. I am using jquery $ .ajax to pass a series of values ββto a web method. The web method takes values, creates an object, and then sends it back as json to the calling page. Once I get the answer, I cannot access the answer and display it.
Can someone explain what I need to do to make this work?
jquery script:
$(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) {
Web method:
[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); }
And the answer I'm returning:
{"d":"\"Name\":\"bob\", \"Company\":\"google\", \"Address\":\"home\", \"Phone\":\"123\", \"Country\":\"usa\"}"}
Here is what I think I should return:
{"Name":"bob", "Company":"google", "Address":"home", "Phone":"123", "Country":"usa"}
The error I get after re-rendering the pages is this:
β’undefined β’undefined β’undefined β’undefined β’undefined