简体   繁体   English

如何将AJAX回调发送到我自己的服务器/ php文件

[英]How to send AJAX callback to my own server/php file

I want to fire up a function when a user hits the button publishes the site with an ajax call and we're having a hard time correcting or fixing this error (No 'Access-Control-Allow-Origin' ). 我想在用户按下按钮并使用ajax调用发布网站时启动一个功能,而我们正难以纠正或修复此错误(No'Access-Control-Allow-Origin')。

Trying this solution: We should be sending the AJAX call back to your own server/php file. 尝试此解决方案:我们应该将AJAX调用发送回您自己的服务器/ php文件。 This PHP file then should send that API call back to Duda directly. 然后,此PHP文件应将该API调用直接发送回Duda。 The flow should be: 流程应为:

 function publish_site() {
    var site_name = $(".site_name").val();
    var url = 'https://mywebsite.com/home/site/'+site_name;
    $.ajax({

            type:'POST',
            data:{site_name:$(".site_name").val()},//Get Account Information
            dataType:'jsonp',
            url:'publish-site.php',
            complete: function(jqXHR, textStatus) {

               $('#publish-btn').toggleClass("btn-primary"); // Revert back to default primary
               $("#publish-btn").html("Publish"); // Change text of button    
               $('.url-here').append('<a href='+url+'>Click here to redirect</a>');
               console.log("Completed: "+textStatus);
            },
            error: function(jqXHR, textStatus, errorThrown) {

                 console.log("Error: "+textStatus+" "+errorThrown);
            },
            success: function(data, textStatus, jqXHR) {

                console.log("Success: "+textStatus);

            },


    });//ajax end
    }//function publish_site end


    $(document).ready(function(){
       $("#publish-btn").click(function(e){
       $("#publish-btn").toggleClass("btn-primary"); // Switch to default grey
       $("#publish-btn").html("Publishing"); // Change text of button    

      publish_site();
     });
    });
    </script>

are u trying this code in your local server then you should download this google chrome extension and enabled it 您是否在本地服务器中尝试此代码,则应下载此Google chrome扩展程序并启用它

https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=zh-CN

or 要么

if it's in your server then please and are you using php then place the this link in your php file 如果它在您的服务器中,那么请您使用的是php,然后将此链接放置在您的php文件中

<?php
 header("Access-Control-Allow-Origin: *");

if you need more information about this then open this link 如果您需要更多有关此的信息,请打开此链接

http://enable-cors.org/server.html http://enable-cors.org/server.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM