开发者

jquery, ajax, php - http request GET http://www.site.dk/?userid=admin&pass=admin 302 Found

开发者 https://www.devze.com 2023-04-11 07:57 出处:网络
Hi i have two wordpress sites in different domains, and i want to pass some values from one to other with ajax ... and can make it ..

Hi i have two wordpress sites in different domains, and i want to pass some values from one to other with ajax ... and can make it ..

Even though the url is working, if i insert this url into address bar it works as expected everyrthing is done and showing but when i try to request it via ajax i get that error (GET http://www.site.dk/?userid=admin&pass=admi开发者_Go百科n 302 Found)

<script type="text/javascript">
$(document).ready(function() {
    // $.post("http://www.site.dk/index.php", { userid: "<?php echo $_REQUEST['userid'] ?>", pass: "<?php echo $_REQUEST['pass'] ?>" } );
    $.getJSON("http://www.site.dk/?userid=<?php echo $_REQUEST['userid'] ?>&pass=<?php echo $_REQUEST['pass'] ?>");
          var dataString = 'userid='+'<?php echo $_REQUEST['userid'] ?>'+'&pass='+'<?php echo $_REQUEST['pass'] ?>'+'';  
    $.ajax({  
      type: "POST",  
      url: "http://www.site.dk/",  
      data: dataString,  
      success: function() {}  
    });  
    return false;  

});
</script>

I have tried also to change url not to real url but to tempalte file url, then getting 500 Internal server error.

And i have tried three different ways, with no success any ideas ?

Thank you


You cannot make an ajax call to another domain. To make AJAX calls, domain / port must match.

There are 2 ways around this:

1) Make an ajax call to the domain you're on & make a GET call from your domain to your second domain.

2) Use JSONP to transfer data from one domain to another.

Also, you seem to be posting some user/password credentials to Javascript, that's not a good idea as everyone can see them.


Can you port those 2 sites into a unique WP MultiSite setup?

If you can manage it, you can acess one site's database from the other. It's kinda tricky to do that because all WP API is meant for a unique site and the whole MultiSite stuff was very badly developed, but it still can be done. Better than use client-side to make 2 sites talk.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号