$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>ajax - Post data across Wordpress sites|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

ajax - Post data across Wordpress sites

matteradmin7PV0评论

I have two Wordpress sites. When I click on a link on Website A (the link is a country) I would like it to navigate to Website B. Website B would then display a list of results based on the link pressed on Website A e.g. the selected country.

The page I would like to navigate to on Website B uses an AJAX POST to retrieve the results though. So it's like I would like to call the AJAX JQuery function on Website B with incoming country name data from website A.

I hope that makes some sense. Is this possible?

I have two Wordpress sites. When I click on a link on Website A (the link is a country) I would like it to navigate to Website B. Website B would then display a list of results based on the link pressed on Website A e.g. the selected country.

The page I would like to navigate to on Website B uses an AJAX POST to retrieve the results though. So it's like I would like to call the AJAX JQuery function on Website B with incoming country name data from website A.

I hope that makes some sense. Is this possible?

Share Improve this question asked Nov 21, 2018 at 14:52 user142553user142553 212 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You can use url parameters (read more here http://php/manual/en/reserved.variables.get.php) but of course you need to create a small function in jQuery / javascript to retrieves those.

For instance, placing a link like https://www.websiteb?country=yourcountry in your Website A and using a get_url_param(country) jQuery function in your Website B, you could pass the value to the AJAX call. I give you a practical example:

Website A

<a href="https://www.websiteb?country=yourcountry">Your Country</a>

Website B

$(document).ready(function(){

   var Country = get_url_param("country");

   //Pass your Country value to the AJAX call
   if(Country != null) init_your_ajax_call(Country);

});

function init_your_ajax_call(param){
   //etc etc
}

function get_url_param(name){
        var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href);
        if (results==null){
           return null;
        } else {
            if(results[1].indexOf("#")){
                results = results[1].split("#");
                results = results[0];
            } else {
                results = results[1] || 0;
            }
            return results;
        }
    }

This function cleans eventual hashes # from the url and retrieves any parameter value you ask for. Returns null whether the parameter doesn't exist.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far