如何在外部API上发送数据?

时间:2019-05-22 09:58:15

标签: json ajax laravel

我想在外部api上发送数据并在页面上接收。实际上,我是新手,可以将数据以JSON格式发送到外部api。 这是我的代码-

<input type="hidden" name="hcodes" class="hcodes" value="{!! $datalist->getData !!}">
<div id="response">
</div>

$(".hcodes").each(function(key,str){
Var hcode = $(str).val();
var jsonData = JSON.stringify({hcode});
    //console.log(jsonData);
      $.ajax({
         url: 'some url',           
             type: "POST",      
        Accept: 'application/json; charset=utf-8',
         api-key: 'providedkey',
        content-type :'application/json',
             dataType: "json", 
             data: jsonData,
             success: function(response){
            alert('success');
             },
             error: function(response){
                alert('error');
             }
        });  

  });

0 个答案:

没有答案