So, I was looking for many different examples of this. Most people use the JSON serializer / deserializer or the stringify method. I tried to try this, and unfortunately I always get an error message from the Google Chrome debugger console saying: Uncaught ReferenceError: JavaScriptSerializer is not defined or something like that.
The following is the actual method in which I try to perform a PUT operation using the information.
function insertjsonMyUser(person) { document.write("Inside the parameter based insertion method<br/>"); alert("Entered the method, right before the ajax call"); $.ajax({ type: "PUT", url: 'http://localhost/MyService/Service.svc/json/CreateUserInfo', contentType: "application/json", data: {"User" : person.User ,"Pword" : person.Pword,"FName" : person.FName,"LName" : person.LName,"JobTitle" : person.JobTitle,"CompanyName" : person.CompanyName,"CompanyBranch" : person.CompanyBranch,"PhoneNum" : person.PhoneNum,"Email" : person.Email}, beforeSend: function(xhr) { xhr.setRequestHeader('Authorization', 'default default'); } }); alert("The user has been created according to your specifications"); }
I want the person to be a JSON object using the specified keys that I have under the data. I have successfully made a similar method, but I do not want to use a hard JSON object, for example:
{"User" : "Zuser" ,"Pword" : "password","FName" : "firstname","LName" : "lastname","JobTitle" : "jobtitle","CompanyName" : "companyname","CompanyBranch" : "companybranch","PhoneNum" : 3123123123,"Email" : "email"}
The JSON object that I use in the hard-coded version is the object above. Is there something I am missing to use stringify or serialize methods? Also, is there an easier way than the ones I missed during the search hours?
Finally, I start Windows 7 Enterprise using IIS hosting and using Visual Studio 2010 for editing. My service is working fine. I successfully tested it in Fiddler.