Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过JS的PHP脚本_Javascript_Php_Wordpress_Geolocation_Currency - Fatal编程技术网

Javascript 通过JS的PHP脚本

Javascript 通过JS的PHP脚本,javascript,php,wordpress,geolocation,currency,Javascript,Php,Wordpress,Geolocation,Currency,我试图通过JS加载一个php脚本,以便能够定位用户并显示与其位置对应的货币。我这样调用php脚本: function determineCurrency() { $.get('/myscript.php').then(function (data) { //... code for changing currency }} } 使用正在调用的geoplugin,更改货币的代码位于determineCurrency函数中 以下是php脚本的内容: <

我试图通过JS加载一个php脚本,以便能够定位用户并显示与其位置对应的货币。我这样调用php脚本:

 function determineCurrency() {
     $.get('/myscript.php').then(function (data) {
         //... code for changing currency
    }}

 }
使用正在调用的geoplugin,更改货币的代码位于determineCurrency函数中

以下是php脚本的内容:

<?php
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$country = $geo["geoplugin_countryName"];
$city = $geo["geoplugin_city"];
?>


没有错误,但代码没有更改货币。

您没有回显或返回任何内容。尝试此操作,然后处理ajax
success()


您没有回显或返回任何内容。尝试此操作,然后处理ajax
success()



您没有从php回显或返回任何内容。另外,ajax调用在哪里?它应该返回一些值,您可以在ajax响应中检索这些值。您没有响应或返回php中的任何内容。ajax调用在哪里?它应该返回一些值,您可以在ajax响应中检索这些值
<?php
    $user_ip = getenv('REMOTE_ADDR');
    $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
    $arr = [
        'user_ip' => $user_ip,
        'geo' => $geo,
        'country' => $geo["geoplugin_countryName"],
        'city' => $geo["geoplugin_city"]
    ];
    echo json_encode ($arr);
    ?>