Reputation: 297
I don't know if my data syntax is wrong or not, but this same script when no parameter is passed is working, but when parameter is passed, it is not working. Why?
<script type="text/javascript" src="jquery-1.7.2.min.js">
<script type="text/javascript">
function GetAge() {
var StrYear = document.getElementById("StringYear").value;
var StrMonth = document.getElementById("StringMonth").value;
var StrDay = document.getElementById("StringDay").value;
jQuery.support.cors = true;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonp: 'jsonp_callback',
async: false,
url: 'http://localhost:50113/Service1.asmx/GetAge',
data: "{ StrYear: "+StrYear+", StrMonth:"+ StrMonth+" , StrDay: "+StrDay+" }",
success: function (msg) {
$('#divToBeWorkedOn').html(msg.d);
},
error: function (e) {
$('#divToBeWorkedOn').html("Unavailable");
}
});
}
</script>
Upvotes: 0
Views: 197
Reputation: 17576
try dataType: "jsonp",
instead of dataType: "json",
and
data: { StrYear: StrYear, StrMonth: StrMonth, StrDay: StrDay },
Upvotes: 1
Reputation: 30453
Probably you should pass data as an object, so probably you don't need
data: "{ StrYear: "+StrYear+", StrMonth:"+ StrMonth+" , StrDay: "+StrDay+" }",
But
data: { StrYear: StrYear, StrMonth: StrMonth, StrDay: StrDay },
Upvotes: 5
Reputation: 6320
Pass your data in this format
data: '{ "StrYear": "' + StrYear+ '","StrMonth":"' + StrMonth+ '" ,"StrDay": "' + StrDay+ '" }',
Upvotes: 1