使用Jquery AJAX将Javascript变量转换为PHP [英] Javascript variable to PHP using Jquery AJAX
本文介绍了使用Jquery AJAX将Javascript变量转换为PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下javascript函数
I have the following javascript function
function success_callback(p)
{
lat = p.coords.latitude.toFixed(2);
lon = p.coords.longitude.toFixed(2);
}
现在我想使用Jquery AJAX将两个变量都传输到PHP,我对Jquery还是很陌生,我不知道该怎么做.我想将变量传输到该JS代码所在的同一个PHP文件中.有可能吗?
Now I want to transfer both the variable to PHP using Jquery AJAX, I am pretty new to Jquery, I am not able to figure out how to do it. I want to transfer the variables to the same PHP file where this JS code resides. Is that possible ?
推荐答案
是的.您可以使用数据字符串发布变量.看看手册.
Yes it is. You could post the variables using the data string. Have a look at the Manual.
$.ajax({
type: "POST",
data: "lat="+lat+"&lon="+lon,
success: function(){
//callback code
alert("Done!");
}
});
这篇关于使用Jquery AJAX将Javascript变量转换为PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文