我在JQuery中有两个函数,第一个函数将地址ip发送到脚本php indexFunctions.php.t这个地址将由第二个函数JQUERY使用。我已成功获取地址ipval .get
。现在我想用@ rpi =" http://" .ip;将这个@ip传递给函数$_POST
。但是当我这样设置时它不起作用$ rpi =" http://192.168.1.15"它工作。我收到此错误
Undefined variable: ip in /var/www/html/web/indexFunctions.php on line 36,
请帮忙。谢谢。
脚本indexFunctions.PHP:
if (isset($_GET['ipval']))
{
$ip=$_GET['ipval'];
}
$rpi="http://".$ip;
if (isset($_POST['stbInfo']))
{
if($_POST['stbInfo']=="On")
{
$url=$rpi.'/StbGetDataModel.php';}
脚本index.PHP:
jQuery(document).ready(function(a) {
setip(ip);
stbStatus(stbInfo);
});
var ip = "192.168.1.15";
function setip(a) {
$.get("indexFunctions.php", {
ipval: a
}, function(a) {
$("#results").html(a);
console.log(a);
}, "html");
}
function stbStatus(a) {
$.post("indexFunctions.php", {
stbInfo: a
}, function(a) {
$("#StbInfo").html(a.text);
}, "json");
}
答案 0 :(得分:0)
必须首先声明var ip =" 192.168.1.15&#34 ;;
变量Ip才能使用setip(ip);
所以你的代码看起来像
var ip = "192.168.1.15";//moved first
jQuery(document).ready(function(a) {
setip(ip);
stbStatus(stbInfo);
});
function setip(a) {
$.get("indexFunctions.php", {
ipval: a
}, function(a) {
$("#results").html(a);
console.log(a);
}, "html");
}
function stbStatus(a) {
$.post("indexFunctions.php", {
stbInfo: a
}, function(a) {
$("#StbInfo").html(a.text);
}, "json");
}
PHP代码:
$ip = isset( $_GET["ipval"] ) ? $_GET["ipval"] : "127.0.1.1";
$rpi = "http://".$ip;
$url = ( isset( $_POST['stbInfo'] ) && $_POST['stbInfo'] == "On" ) ? $rpi.'/StbGetDataModel.php' : $rpi.'/StbGetDataModel.php' ;
答案 1 :(得分:0)
if (isset($_GET['ipval']))
{
$ip=$_GET['ipval'];
}
$rpi="http://".$ip;
如果Isset为FALSE,他仍然会尝试在第4行使用$ ip