使用 Jquery 将数据从 javascript 传递到 php
也许这个问题以前已经被问过,但我正在努力做到这一点。我有一个 php 文件,其中不包含任何 php 代码(可能在将来),它只包含 javascript 和一些 html。我想要做的是单击此 php 文件中的按钮将一些数据发送到另一个 php 文件。 这样说吧..
1-我在 a.php 中有一个 saveProfile 函数,并且有一个按钮正在调用该函数
function saveProfile (){
var variableD = 'sample data';
$.post("dbConn.php", { js: variableD});
}
2-我有另一个名为 dbConn.php 的 php,它接收数据并存储在数据库表中。
我已经找到很多例子了。我已经应用了它们,但它仍然不起作用,让我发疯。我是一名 java 程序员,但对 php 很陌生。 感谢任何帮助。给我一些干净的示例代码,或者如果您发现任何错误,请警告我。提前感谢大家...
问候。 奥兹莱姆。
Maybe this question has been asked before but I am struggling in doing this. I have got a php file which does not include any piece of php code (might be in the future),it includes just javascript and some html. What I want to do is clicking a button in this php file to send some amount of data to another php file.
put it this way..
1-I have got a saveProfile function in a.php and a button is calling this function
function saveProfile (){
var variableD = 'sample data';
$.post("dbConn.php", { js: variableD});
}
2-I have got another php which is called dbConn.php that receives data and stores in a database table.
I have found so many examples. I have applied them but it still does not work and is driving me nuts. I am a java programmer but new in php.
Any help is appreciated.give me some clean sample code or if you see any mistake please kindly warn me. Thanks to all in advance...
Regards.
Ozlem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看已接受的答案“< a href="https://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit">Javascript Post 请求,如表单提交”。
它提供了 javascript for:
我认为这会做你想要的。
Take a look at the accepted answer to "Javascript Post Request like a Form Submit".
It provides javascript for for:
I think this will do what you want.
感谢所有的答案。我已经解决了这个问题。数据已通过,但我无法正确处理。我只是添加了一个虚拟代码来测试它。它有效。完成后我会上传代码。谢谢大家。
Thanks for all the answers. I have solved the problem. The data had being passes but I was not able to handle it properly. I just add a dummy code to test it.It worked. I will upload the code after I have finished.Thanks to all.
该函数位于 PHP 文件中,但充满了 JS 代码。最后一行将数据传递到另一个 PHP 文件,该文件将数据保存到数据库中。
这是 dbConn.php,由
saveProfile
方法调用。数据处理如下:This function is in a PHP file, but is full of JS code. The last line passes the data to another PHP file which saves the data into a database.
This is dbConn.php, which is called by the
saveProfile
method. The data is handled as follows: