<bdo id='LwMtD'></bdo><ul id='LwMtD'></ul>

  • <legend id='LwMtD'><style id='LwMtD'><dir id='LwMtD'><q id='LwMtD'></q></dir></style></legend>

      <i id='LwMtD'><tr id='LwMtD'><dt id='LwMtD'><q id='LwMtD'><span id='LwMtD'><b id='LwMtD'><form id='LwMtD'><ins id='LwMtD'></ins><ul id='LwMtD'></ul><sub id='LwMtD'></sub></form><legend id='LwMtD'></legend><bdo id='LwMtD'><pre id='LwMtD'><center id='LwMtD'></center></pre></bdo></b><th id='LwMtD'></th></span></q></dt></tr></i><div id='LwMtD'><tfoot id='LwMtD'></tfoot><dl id='LwMtD'><fieldset id='LwMtD'></fieldset></dl></div>
      1. <tfoot id='LwMtD'></tfoot>

        <small id='LwMtD'></small><noframes id='LwMtD'>

        Jquery AJAX:请求的资源上不存在“Access-Control-Allo

        时间:2023-10-14
          <tbody id='eeXsc'></tbody>

        • <legend id='eeXsc'><style id='eeXsc'><dir id='eeXsc'><q id='eeXsc'></q></dir></style></legend>
            <i id='eeXsc'><tr id='eeXsc'><dt id='eeXsc'><q id='eeXsc'><span id='eeXsc'><b id='eeXsc'><form id='eeXsc'><ins id='eeXsc'></ins><ul id='eeXsc'></ul><sub id='eeXsc'></sub></form><legend id='eeXsc'></legend><bdo id='eeXsc'><pre id='eeXsc'><center id='eeXsc'></center></pre></bdo></b><th id='eeXsc'></th></span></q></dt></tr></i><div id='eeXsc'><tfoot id='eeXsc'></tfoot><dl id='eeXsc'><fieldset id='eeXsc'></fieldset></dl></div>
            <tfoot id='eeXsc'></tfoot>

                  <bdo id='eeXsc'></bdo><ul id='eeXsc'></ul>

                  <small id='eeXsc'></small><noframes id='eeXsc'>

                  本文介绍了Jquery AJAX:请求的资源上不存在“Access-Control-Allow-Origin"标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

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

                  I am trying to post data to an API from my localhost:4502 port. When i tried to post data to this API using POSTMAN the data got added in the backend by providing the Basic Authorization key. The same i am trying to implement here in the Ajax Jquery call, but getting an CORS error. First time in jquery i am trying to post the data, please help here, what i can add. I have got the API key to for the Basic Authorization as a Username and Password can be left blank.

                    <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>
                  

                  推荐答案

                  我已经添加了 dataType: 'jsonp' 并且它有效!

                  I have added dataType: 'jsonp' and it works!

                  $.ajax({
                     type: 'POST',
                     crossDomain: true,
                     dataType: 'jsonp',
                     url: '',
                     success: function(jsondata){
                  
                     }
                  })
                  

                  JSONP 是一种发送 JSON 数据的方法,无需担心跨域问题.阅读更多

                  JSONP is a method for sending JSON data without worrying about cross-domain issues. Read More

                  这篇关于Jquery AJAX:请求的资源上不存在“Access-Control-Allow-Origin"标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用跨域资源共享的跨域 POST 查询没有返回数据 下一篇:使用 img.crossOrigin = "Anonymous" 将图像绘制到

                  相关文章

                  最新文章

                  <legend id='qMR6X'><style id='qMR6X'><dir id='qMR6X'><q id='qMR6X'></q></dir></style></legend>
                • <tfoot id='qMR6X'></tfoot>

                    <i id='qMR6X'><tr id='qMR6X'><dt id='qMR6X'><q id='qMR6X'><span id='qMR6X'><b id='qMR6X'><form id='qMR6X'><ins id='qMR6X'></ins><ul id='qMR6X'></ul><sub id='qMR6X'></sub></form><legend id='qMR6X'></legend><bdo id='qMR6X'><pre id='qMR6X'><center id='qMR6X'></center></pre></bdo></b><th id='qMR6X'></th></span></q></dt></tr></i><div id='qMR6X'><tfoot id='qMR6X'></tfoot><dl id='qMR6X'><fieldset id='qMR6X'></fieldset></dl></div>

                        <bdo id='qMR6X'></bdo><ul id='qMR6X'></ul>
                    1. <small id='qMR6X'></small><noframes id='qMR6X'>