Jquery .getJson()意外令牌:

时间:2015-12-27 09:06:00

标签: jquery json ajax web-services

当我尝试访问以下网址时:

http://dhclinicappv2stg.item-soft.co.il/LinkCareAppService.svc/json/GetFinalReportToAccount?AccountId=123

我收到了JSON服务响应。我试图通过Jquery读取这个响应,如下:

   (function()
      {
         var serviceAPI = "http://dhclinicappv2stg.item-soft.co.il/LinkCareAppService.svc/json/GetFinalReportToAccount?AccountId=?";
         $.getJSON( serviceAPI,
        {
          AccountId: "123"
         })
         .done(function( data )
         {
           alert(data);
         });
        })();
<!doctype html>
    <html lang="en">
      <head>
         <meta charset="utf-8">
         <title>jQuery.getJSON attempt</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      </head>
    <body>
 
    <div id="data"></div> <!-- in the future, I will add the data to this div -->
 
    <script>
   
      </script>
 
      </body>
    </html>

然而,我得到一个空白页面,没有警报。控制台日志读取标题中的错误。

我做错了什么?

1 个答案:

答案 0 :(得分:2)

服务没有问题。由于此服务调用已触发,因此只有您的服务网址错误才会删除?AccountId=?

/GetFinalReportToAccount?AccountId=jQuery21101485728188417852_1451208967751&AccountId=123&_=1451208967752

尝试以下工作代码段,其中参数已删除getJSON方法的网址。

&#13;
&#13;
(function() {
   var serviceAPI = "http://dhclinicappv2stg.item-soft.co.il/LinkCareAppService.svc/json/GetFinalReportToAccount";
   $.getJSON(serviceAPI, {
           AccountId: "123"
       })
       .done(function(data) {

          $('#data').text(JSON.stringify(data));
       });
})();
&#13;
    <!doctype html>
        <html lang="en">
          <head>
             <meta charset="utf-8">
             <title>jQuery.getJSON attempt</title>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
          </head>
        <body>
     
        <div id="data"></div> <!-- in the future, I will add the data to this div -->
     
          </body>
        </html>
&#13;
&#13;
&#13;