如何从JavaScript传递价值的PHP文件 [英] How to pass value from javascript to php file
问题描述
我通过 JQuery的
获得价值为这样的事情
I am getting value via JQuery
as something like this
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
var id = dim[1].split('=')[1];
现在我要发送或得到这个身份证
值转换成同一 PHP
文件。我想我们可以PHP 页使用 GET
方法仅得到其他值。我想获得的价值在同一
PHP
文件。
Now i want to send or get this "id"
value into same php
file. I think we can only get value on other php
page using get
method. I want to get value on same php
file.
我想我们可以用这个用做 AJAX
吧?
I think we can do with this using AJAX
right?
如果有,请给我一些链接或code如何获得?我是新手到 AJAX
。
If yes please give me some links or code how to get? I am newbie to ajax
.
推荐答案
好吧,如果你只是想将数据发送到服务器,你不想要检索什么都重要,不知道或不想使用AJAX,一个更简单的解决方案是将附加的所需的URL上的隐藏的DOM对象。如:
< IMG SRC =http://my-host.com/my-script.php?id=+ ID样式=显示:无;/>
well, if you only want to send that data to the server and you don't want to retrieve anything else and don't know or don't want to use ajax, a more simpler solution would be to attach the desired url on a hidden dom object. such as :
<img src="http://my-host.com/my-script.php?id="+id style="display:none;"/>
巫可以添加到以多种方式的dom
witch can be added to the dom in multiple ways.
如果你想使用AJAX,我建议使用一个库,如jQuery的,至极进行了优化,跨浏览器的Web应用程序。使用jQuery,语法很简单:
If you want to use ajax, I recommend using a library such as jQuery, wich is optimized for cross-browser web apps. With jQuery, the syntax is very simple :
$.get(
"http://my-host.com/my-script.php",
{"id" : id},
function(data){
// do something with the response
}
);
你可以使用后,而不是得,这取决于你的需求。我建议你在 jQuery的文档峰值。
You could use "post" instead of "get" depending on your needs. I recommend you take a peak at jQuery documentation.
这篇关于如何从JavaScript传递价值的PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!