how to change data at DB from jquery-ui dialog?

岁酱吖の 提交于 2020-02-07 04:57:47

问题


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?


回答1:


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/




回答2:


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



来源:https://stackoverflow.com/questions/3370219/how-to-change-data-at-db-from-jquery-ui-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!