小编Ash*_*Rai的帖子

Jquery AJAX:请求的资源上没有"Access-Control-Allow-Origin"标头

我试图从我的localhost:4502端口将数据发布到API.当我尝试使用POSTMAN将数据发布到此API时,通过提供基本授权密钥将数据添加到后端.我试图在Ajax Jquery调用中实现这一点,但得到一个CORS错误.第一次在jquery我试图发布数据,请在这里帮助,我可以添加.我有基本授权的API密钥,因为用户名和密码可以留空.

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

  <script>
               $(document).ready(function(){
               $("#Save").click(function(){

                  var person = new Object();
                  person.Name = $('#Name').val();
                  person.EmailAddress = $('#EmailAddress').val();
                  person.CustomFields = [0];
                  person.CustomFields[0].Key = "[Country]";
                  person.CustomFields[0].Value = $('#Country').val();;

               $.ajax({
                 url: 'https://api.createsend.com/api/v3.1/subscribers/7c7a6087b0e450ad72b38be83098e271.json',
                 type: 'POST',
                 dataType: 'json',
                 data:person,
                 success: function(data,textStatus,xhr){

                     console.log(data);
                 },
                 error: function(xhr,textStatus,errorThrown){
                     console.log('Error Something');
                 },
                 beforeSend: function(xhr) {

                    xhr.setRequestHeader("Authorization", "Basic OTdlMjVmNWJiMTdjNzI2MzVjOGU3NjlhOTI3ZTA3M2Q5MWZmMTA3ZDM2YTZkOWE5Og=="); 
                 }
             });
         });
     });
  </script>
Run Code Online (Sandbox Code Playgroud)

ajax jquery cors aem

18
推荐指数
3
解决办法
10万
查看次数

标签 统计

aem ×1

ajax ×1

cors ×1

jquery ×1