Javascript 无法使用ajax调用将值传递给Web服务
我不知道我的数据语法是否错误,但在没有传递参数的情况下,这个脚本是有效的,但在传递参数的情况下,它是无效的。为什么?Javascript 无法使用ajax调用将值传递给Web服务,javascript,jquery,html,json,Javascript,Jquery,Html,Json,我不知道我的数据语法是否错误,但在没有传递参数的情况下,这个脚本是有效的,但在传递参数的情况下,它是无效的。为什么? <script type="text/javascript" src="jquery-1.7.2.min.js"> <script type="text/javascript"> function GetAge() { var StrYear = document.getElementById("Stri
<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>
以这种格式传递数据
data: '{ "StrYear": "' + StrYear+ '","StrMonth":"' + StrMonth+ '" ,"StrDay": "' + StrDay+ '" }',
可能应该将数据作为对象传递,所以可能不需要
data: "{ StrYear: "+StrYear+", StrMonth:"+ StrMonth+" , StrDay: "+StrDay+" }",
但是
尝试dataType:jsonp,而不是dataType:json
及
thanx的代码,但它没有任何效果,这是我的jquery-1.7.2.min.js的问题吗?使用它来检查问题是什么错误:函数xhr,ajaxOptions,thrownError{alertxhr.responseText;alertthrownError;},thanx的代码,但它没有效果是不是我的jquery-1.7.2.min.jsit不工作的问题意味着什么?控制台中有错误吗?请求正确吗?反应如何?fiddler/net选项卡
data: { StrYear: StrYear, StrMonth: StrMonth, StrDay: StrDay },
data: { StrYear: StrYear, StrMonth: StrMonth, StrDay: StrDay },