开发者

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

开发者 https://www.devze.com 2023-01-09 07:24 出处:网络
i\'m newbie,i want change my DB data from jquery-ui dial开发者_高级运维og. What code should I add to the dialog script that can make me connecting to process page before connecting to DB?In your jquer

i'm newbie,i want change my DB data from jquery-ui dial开发者_高级运维og. What code should I add to the dialog script that can make me connecting to process page before connecting to DB?


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/


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

0

精彩评论

暂无评论...
验证码 换一张
取 消