In the background of their own CMS, want to be on the same page with a pop-up mask layer of the way to modify member information
Getting userid is a big problem.
Last colleague's advice with $.ajax
| The code is as follows |
Copy Code |
|
$ (' p.editinfo>a '). Bind (' click ', function () {
$ (' #edit_uid '). Val ($ (this). attr ("UID"));
Alert ($ (this). attr ("UID"));
var uid= $ (this). attr ("UID");
alert (vote_content);
$.ajax ({
Type: ' Get ',
DataType: ' JSON ',
URL: ' user_edit.php ',
Data: ' uid= ' + uid,
Success:function (JSON) {
$ (' #username '). Val (Json.username); Assign a value to a corresponding JOSN value
$ (' #mid_1 '). Val (Json.mid);
$ (' #new_password '). Val (Json.password);
$ (' #uid_edit '). Val (Json.uid);
},
Error:function () {}
});
});
}); |
The user_edit.php used to receive is the normal PHP SQL statement
Use the Json_encode function (refer to Php-json_encode)
| The code is as follows |
Copy Code |
|
$uid = $_get[' uid '];
$query _admin_1 = $db->find ("table where uid= ' $uid ')";
$row _admin_1 = $db->fetch_array ($query _admin_1);
$userinfo = Json_encode ($row _admin_1);
Echo $userinfo; |
The resulting $userinfo for JSON data storage format
A standard HTML form that receives JSON data
| code is as follows |
copy code |
|
<div class= "txt-fld"
<label for= "" > User name </label>
<input id= "username" class= "good_input" name= "username" type= "text"
</div>
<div class= "txt-fld"
<label for= "" > User password/label>
<input id= "New_password" name= "new_password" type= "password" />
</div> |
Note that the Ajax operating part is not quite the same as it is, only in datatype: ' JSON ', and then we access the content in Json.mid this form, in fact, like the array $a[' a ', where JSON is a returned array, Mid is the ID we returned.