Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法使用ajax调用将值传递给Web服务_Javascript_Jquery_Html_Json - Fatal编程技术网

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 },