当我单击一个按钮时,它会创建一个变量 $var 然后我想将此 var 发送到 php 来处理它。
例子:
在 Jquery.js 中
$('#button').click(function(){
//create the var
$name = "abcde";
//send the $name to process.php
---I DONT KNOW HOW---
});
在 process.php 中
只是...
echo $name;
如何发送 $name ???
当我单击一个按钮时,它会创建一个变量 $var 然后我想将此 var 发送到 php 来处理它。
例子:
$('#button').click(function(){
//create the var
$name = "abcde";
//send the $name to process.php
---I DONT KNOW HOW---
});
只是...
echo $name;
如何发送 $name ???
$.get("url", {name: "abcde"}, function(response){
//Do something
});
$.post("url", {name: "abcde"}, function(response){
//Do something
});
在jQuery代码中
$.post('process.php',name:$name,function(data){alert(data);});
在 process.php 中
if(isset($_POST['name'])){
echo $_POST['name'];
}else{
echo 'nothing was send';
}
$('#button').click(function(){
var $name = "abcde";
$.ajax({
type: 'POST',
url: process.php,
data: {name:$name},
success: function(data){alert("send ok")}
});
});
进程.php:
if(isset($_POST['name'])){
echo $_POST['name'];
}