Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.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 jspajax返回NULL_Javascript_Jquery_Ajax_Jsp_Null - Fatal编程技术网

Javascript jspajax返回NULL

Javascript jspajax返回NULL,javascript,jquery,ajax,jsp,null,Javascript,Jquery,Ajax,Jsp,Null,我使用jqueryajax在jsp中调用restapi,但无论我如何调用它,它都返回null,但它可以在html中工作。有没有办法解决这个问题。在网上似乎找不到解决办法 数据类型应为jsonp $(document).ready(function () { var thisUrl = 'http://www.onemap.sg/API/services.svc/getToken?accessKEY=' + accessKey; $.ajax({ type: "G

我使用jqueryajax在jsp中调用restapi,但无论我如何调用它,它都返回null,但它可以在html中工作。有没有办法解决这个问题。在网上似乎找不到解决办法



数据类型应为
jsonp

$(document).ready(function () {
    var thisUrl = 'http://www.onemap.sg/API/services.svc/getToken?accessKEY=' + accessKey;
    $.ajax({
        type: "GET",
        url: thisUrl,
        dataType: 'jsonp',
        success: function (data) {
            console.log(data)
            alert('data is:' + data.GetToken[0].NewToken);
        }
    });
});
请参阅本文:

您只需要示例源代码中的“jquery.xdomainajax.js”就可以使其正常工作

$.ajax({
          url: 'https://asdf/asdf',
          dataType: "xml",
          type: 'GET',
          success: function(res) {
          var myXML = res.responseText;
          alert(myXML);
        }
      });

您好,它仍然返回未定义。@user2627054添加一个
console.log(data)
并查看
数据中有什么内容
您不能只使用@ArunPJohny提供给您的代码。他正在硬编码一个3的accessKey。他的代码有效,但返回无效的访问代码error@jasonscript你可以使用他的代码,但是你必须确保你传递了正确的accessKey值。您也在代码中设置了它,但您必须在某个地方有一个全局变量。我只是想让你们知道,你们不能直接复制粘贴他的代码,并期望它能工作。你们可能不应该把你们的访问密钥放在一个公共场合,因为accesskey是公共密钥,它只在本地主机上工作。我没有邮寄我的私人钥匙
$.ajax({
          url: 'https://asdf/asdf',
          dataType: "xml",
          type: 'GET',
          success: function(res) {
          var myXML = res.responseText;
          alert(myXML);
        }
      });