将一个JavaScript变量传递给php
问题描述:
我有问题将一个javascript变量传递给php代码。将一个JavaScript变量传递给php
,我使用PHP的代码是:
$image= $this->user_gallerymodel->viewAlbumImage();
我只需要JavaScript变量通过在模型函数的参数。使用location.href
答
可以调用控制器..这重新加载页面
var jvVar="test";
window.location="controller/path/" + jvVar;
wihtout重装您可以使用Ajax来发送VAR ..
var jvVar="test";
$.post("controller/path/test",{value:jvVar},function(data){
alert(data);
});
,并在你contorller说测试( )..得到它的后..
<?php
function test(){
$value=$this->input->post('value');
echo $value;
}
答
你可以使用Ajax调用其中值co ntains你想发回的价值。
$.ajax({
url: "test.php",
type: "post",
data: values,
success: function(){
alert("success");
$("#result").html('Value Saved');
},
error:function(){
alert("failure");
$("#result").html('there was an error while saving value');
}
});