Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
Jquery 在《邮递员》中,试图获得一份工作的结果非常有效,但在浏览器中使用AJAX需要app_代码和app_id_Jquery_Ajax_Postman_Here Api - Fatal编程技术网

Jquery 在《邮递员》中,试图获得一份工作的结果非常有效,但在浏览器中使用AJAX需要app_代码和app_id

Jquery 在《邮递员》中,试图获得一份工作的结果非常有效,但在浏览器中使用AJAX需要app_代码和app_id,jquery,ajax,postman,here-api,Jquery,Ajax,Postman,Here Api,我正在尝试使用herejobsrestapi来获得我的工作结果。我在Postman中测试了我的GET请求,它使用我的apiKey工作得非常好,没有使用任何额外的头(除了内容类型:application/octet stream) 但是当我尝试使用AJAX和jQuery来尝试相同的请求时,我得到一个400响应,告诉我需要一个app_id和app_代码。 我的代码: $.ajax({ async: false, contentType: "applicati

我正在尝试使用herejobsrestapi来获得我的工作结果。我在Postman中测试了我的GET请求,它使用我的apiKey工作得非常好,没有使用任何额外的头(除了内容类型:application/octet stream)

但是当我尝试使用AJAX和jQuery来尝试相同的请求时,我得到一个400响应,告诉我需要一个app_id和app_代码。 我的代码:

    $.ajax({
        async: false,
        contentType: "application/octet-stream",
        type: 'GET',
        url: "https://batch.geocoder.ls.hereapi.com/6.2/jobs/{JOB_ID}/result?apiKey={API_KEY}",
    }).done(function (result) {
        console.log(result);
    });
{"error":"Bad Request","error_description":"The request is missing the app_id and app_code parameters. They must both be passed as query parameters. If you do not have app_id and app_code, please obtain them through your customer representative or at http://developer.here.com/myapps."}
返回标题:

    $.ajax({
        async: false,
        contentType: "application/octet-stream",
        type: 'GET',
        url: "https://batch.geocoder.ls.hereapi.com/6.2/jobs/{JOB_ID}/result?apiKey={API_KEY}",
    }).done(function (result) {
        console.log(result);
    });
{"error":"Bad Request","error_description":"The request is missing the app_id and app_code parameters. They must both be passed as query parameters. If you do not have app_id and app_code, please obtain them through your customer representative or at http://developer.here.com/myapps."}
将此普通链接放入浏览器的URL栏时,使用此链接确实有效

使用REST下页面上的应用程序id和api密钥的组合作为api_代码也不起作用。这告诉我这是一对无效的

我不知道我现在应该使用什么凭证

提前谢谢你的帮助

根据,您必须使用
apikey
进行身份验证。 请检查这段代码的ajax,它工作正常

<html>
<button type="button" class="btn">Click me!</button>
<p class="text">Replace me!!</p>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$('.btn').click(function() {

  $('.text').text('loading . . ');

  $.ajax({
  type:"GET", 
 url:"https://batch.geocoder.ls.hereapi.com/6.2/jobs/CxnGVvxLZeCjJnGRD0udKgLgeQzNa5xq/result?apiKey={apikey}",
    success: function(result) {
      $('.text').text(JSON.stringify(result));
      console.log(result);
    },

  });

  });
 </script>
 </html>

点击我!

替换我

$('.btn')。单击(函数(){ $('.text').text('加载..'); $.ajax({ 键入:“获取”, url:“https://batch.geocoder.ls.hereapi.com/6.2/jobs/CxnGVvxLZeCjJnGRD0udKgLgeQzNa5xq/result?apiKey={apikey}“, 成功:功能(结果){ $('.text').text(JSON.stringify(result)); 控制台日志(结果); }, }); });

希望这能有所帮助。

我的问题是contentType,删除了它就可以工作了。非常感谢。