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 badges1 Answer
Reset to default 0You 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.