[英]javascript:variable value passing from javascript to php
I have a javascript
file pet.js
. 我有一个javascript
文件pet.js
I want to pass a value of variable in test.php
. 我想在test.php
传递变量的值。 But i can't. 但是我不能。
my pet.js
is like 我的pet.js
就像
$('#pmWorkOrderDetailsPage').live('pageshow', function(event) {
var id = getUrlVars()["id"];
$.get("test.php", { test1: id } );
$.getJSON('pmworkorderdetails.php?id='+id, displaypmWODetails);
});
function displaypmWODetails(data) {
..............code..........
}
My test.php
is like 我的test.php
就像
<?php
$ms = $_GET["test1"];
echo $ms;
?>
But it is not working. 但这是行不通的。 I tried with Ajax
and post
method. 我尝试了Ajax
和post
方法。
It will be best if I can store the variable value on the session in test.php. 最好将变量值存储在test.php中。
Thanks in advance for any help. 在此先感谢您的帮助。
1 do not use getUrlVars()
it can make site vulnerable to xss 1不要使用getUrlVars()
会使站点容易受到xss的攻击
$('#pmWorkOrderDetailsPage').live('click', function(event) {
var id;// get id
$.get("test.php?id="+id,function(data){
var result=$.parseJSON(data);
alert(result["content"])
});
})
test.php test.php
<?php
$id=$_GET['id'];
$data=array();
$data=array("content"=>$id);
echo json_encode($data);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.