0

What is wrong with this code? I am trying to pass parameters to a WCF function. I couldn't get this to work. I am getting Ajax error.

  $.ajax({
    url: applicationPath + "/Test.svc/GetData",
    type: "POST",
    dataType: "json",
    data: '{GId":' + sender.get_value() + '"GName":' + sender.get_text() + '"mId":' + testId + '}',
    contentType: "application/json; charset=utf-8",
    success: function(result)
    {
        //trying to fill combobox here
    },
});
Hello71
  • 766
  • 8
  • 17
nav100
  • 411
  • 1
  • 10
  • 26

1 Answers1

0

The data is not valid JSON. What follows is the code and an example of its result.

'{GId":' + sender.get_value() + '"GName":' + sender.get_text() + '"mId":' + testId + '}'
>> '{GId":'foo'"GName":'bar'"mId":5}'

Instead of constructing JSON manually, I would use JSON.stringify and pass it an object.

JSON.stringify({GId: sender.get_value(), GName: sender.get_text(), mId: testid})
>> "{"GId":"df","GName":"sdf","mId":4}"

I think you can see there is a difference. Your code was missing commas and a quotation mark at the beginning of GId.

Reiner Gerecke
  • 11,936
  • 1
  • 49
  • 41