2013-01-21 116 views
0

可能重复:
How to pass JavaScript variables to PHP?
Passing a Javascript string to PHP返回JavaScript函数PHP变量

我有这个JavaScript的PHP文件中的代码:

<script> 
function(){ 
var mail="[email protected]"; 
for(var i=0; i<json_load.length; i++){ 
    if(json_load[i].custom.tipologo == "FAAC FILIALI"){ 
     mail=json_load[i].custom.email; 
    } 
} 
return mail; 
} 
</script> 

我需要将“邮件”变量返回给PH P变量。我怎样才能做到这一点??

+0

邮政/ get是trasnmitting数据的标准方法通过http – DavidB

+0

这么多重复的问题,这是很难知道哪些链接到。您需要了解Ajax,以及更一般地了解客户端/服务器环境(如浏览器/ Web服务器)中的prorgams如何工作。 – SDC

回答

2

要么通过jQuery中的submit()提交邮件变量,要么使用AJAX

手册:AJAXsubmit

$.ajax({ 
    type: "POST", 
    url: window.location.href, 
    dataType: "json", 
    data: mail,  
    success: function(response) { 
     //do something with response  
    } 
}); 
0

如果你了解的基础知识,你不能传递的Java脚本值到PHP变量。因为PHP在服务器端呈现,并且java脚本在客户端呈现。 Read this

你可以做的是,你可以将数据传递到使用AJAX服务器,

$.ajax({ 
    type: "POST", 
    url: path/to/the/php/file.php, 
    mail: mail,  
    success: function(response) { 
    //if you return something from the server-side you get it here  
    } 
});