0

In www.example1.com/demo.php I have a variable named

$x=5

I want to display the value of $x in www.example2.com

How to do it?

www.example2.com does not have server-side language support. Can I do it with JavaScipt or does it have a another way to accomplish it?

Máté
  • 2,294
  • 3
  • 18
  • 25
  • 1
    Just send the param as a query parameter in the URL (`www.example2.com?x=5`) and fetch it in the new site using JS. [Here's a post about that](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – M. Eriksson Oct 07 '19 at 05:37
  • 4
    the short answer is AJAX – Bravo Oct 07 '19 at 05:43

1 Answers1

1

javascriptWantValue.js :

// show the waiting circle gif animation ;
$("#waitingCircle").css("display", "block");

$.ajax({
    url: "getValueFromPhp.php?"+paramOptional,
    dataType: "text",
    async: true,
    success: makeuseofValueFromPhp
});

function makeuseofValueFromPhp(valueFromPhp, status123, XHR123) {

    console.log("value from php is : " + valueFromPhp);

    // hide the waiting circle ;
    $("#waitingCircle").css("display", "none");

}// end function makeuseofValueFromPhp()

getValueFromPhp.php is :

<?php
    $x = 5;
    echo $x;
?>
Winston L
  • 53
  • 6