I have a jQuery call like this, which gives me a lot of problems:
$('#submit').click(function () {
var url = "/home/start";
var notifyEmail = $("#notify_email").val();
var receiverPhone = $("#receiver_phone").val();
var sliderValue = $("#slider").slider("value");
var dataToSend = '{phoneReceiver:' + receiverPhone + ', emailNotify:' + notifyEmail + ', value:' + sliderValue + '}';
//var dataToSend = '{"phoneReceiver":"' + receiverPhone + '", "emailNotify":"' + notifyEmail + '", "value:"' + sliderValue + '"}';
$.ajax({
type: "POST",
url: url,
data: dataToSend,
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (data) {
alert('Awesome destination: ' + data.DestinationAddress);
},
error: function (date) {
alert('An occurred while purchasing. Please try again later');
}
});
});
I’ve tried fiddling with the data formatting (as you can see there are two versions) and with/without dataType and contentType. No luck yet.
I have the following problems:
- I get an 500 Internal server error, which looks like formatting errors
- The call is not made as json in FireBug. When selecting the json tab there is nothing, but the post has
Because of this, my breakpoint inside the webservice, is never hit.
All the parameters in the data is fine.
In FireBug, I can see my post is:
{phoneReceiver:fgsdfg, emailNotify:dgsg, value:19}
Or:
{"phoneReceiver":"gfjhfghj", "emailNotify":"fjhfgjhgj", "value:"16"}
Any hints?
I was able to get your code working as follows: