如何从 jquery-ui 对话框更改数据库中的数据?

发布于 2024-09-11 17:59:55 字数 165 浏览 1 评论 0原文

我是新手,我想从 jquery-ui dialog 更改我的数据库数据。 我应该在对话框脚本中添加哪些代码,以便在连接到数据库之前连接到进程页面?

i'm newbie,i want change my DB data from jquery-ui dialog.
What code should I add to the dialog script that can make me connecting to process page before connecting to DB?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋叶绚丽 2024-09-18 17:59:55

在你的 jquery-ui 对话框中,你应该有一个按钮,当你按下它时,它会更新数据库表中的一行。为了做到这一点:

- 创建一个按钮,当按下它时,它将触发对 php 文件的 ajax 请求:

$('#MyButton').click(function() {
 $.ajax({
 type: "GET",
 url: "MyPage.php",
 data: "id=3",
 cache: false,
 error: function (msg) {},
 success: function (msg) {}
 });
});

- 在你的 php 文件中,你将有一个更新数据库表中的行的脚本:

<?php
mysql_connect("Host", "Login", "Password) OR trigger_error(mysql_error(), E_USER_ERROR);
mysql_select_db("DatabaseName") OR trigger_error(mysql_error(), E_USER_ERROR);
mysql_query("UPDATE tableName SET myValue = 'value' WHERE condition = 'value'") OR trigger_error($query, E_USER_ERROR);
?>

这是一个非常简单的示例,我建议阅读以下教程:

http://php4every1.com/tutorials/jquery-ajax -教程/

In your jquery-ui dialog you should have let say a button, and when you press it, it would update a row in a database table. In order to do it:

-Create a button, and when pressed it would trigger an ajax request to a php file:

$('#MyButton').click(function() {
 $.ajax({
 type: "GET",
 url: "MyPage.php",
 data: "id=3",
 cache: false,
 error: function (msg) {},
 success: function (msg) {}
 });
});

-In your php file you would have a script updating the row in the database table:

<?php
mysql_connect("Host", "Login", "Password) OR trigger_error(mysql_error(), E_USER_ERROR);
mysql_select_db("DatabaseName") OR trigger_error(mysql_error(), E_USER_ERROR);
mysql_query("UPDATE tableName SET myValue = 'value' WHERE condition = 'value'") OR trigger_error($query, E_USER_ERROR);
?>

This is a really simple example, I would recommend reading the following tutorials:

http://php4every1.com/tutorials/jquery-ajax-tutorial/

白龙吟 2024-09-18 17:59:55

我不确定你是否理解你所问的问题。 JavaScript不能直接修改服务器上的数据,它需要通过向服务器传递数据来调用服务器上的 PHP、C#、Perl 或其他脚本。然后,该服务器端脚本会修改您的数据库。

如果是 PHP,您的 Javascript 可能会发出包含以下内容的 POST 请求:

name=Dave&phone_number=12345

您的 PHP 脚本将使用 $_POST['name']$_POST['phone_number'] 访问该数据并将其发送到数据库。我会推荐一些背景阅读,例如:
动态应用程序开发-Using-MySQWeb-Application-Architecture-Principles-Protocols< /a> 或 PHP-MySQL-Dynamic-Web -站点jQuery 的实际应用< /a>

I am not sure you understand the question you are asking. Javascript can't directly modify data on your server, it needs to invoke a PHP, C#, Perl or other script on the server by passing data to it. This server-side script then modifies your database.

If it were PHP your Javascript might make a POST request containing:

name=Dave&phone_number=12345

Your PHP script would then use $_POST['name'] and $_POST['phone_number'] to access that data and send it to the database. I would recommend some background reading such as:
Dynamic-Application-Development-Using-MySQ or Web-Application-Architecture-Principles-Protocols or PHP-MySQL-Dynamic-Web-Sites and jQuery in action

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文