This article will introduce the interaction between ajax and json data. In the past, ajax post, get, AND htm and txt data were directly returned. This is a try to return json data.
In your own background cms, you want to use the pop-up mask layer on the same page to modify member information.
Getting UserID is a big problem
Finally, my colleague suggested using $. 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 the corresponding josn.
$ ('# Mid_1'). val (json. mid );
$ ('# New_password'). val (json. password );
$ ('# Uid_edit'). val (json. uid );
},
Error: function (){}
});
});
}); |
User_edit.php is a normal php SQL statement.
Use the json_encode function (refer to the 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 is in json data storage format.
Standard html form for receiving json data
| The Code is as follows: |
Copy code |
|
<Div class = "txt-Example">
<Label for = ""> User Name </label>
<Input id = "username" class = "good_input" name = "username" type = "text"/>
</Div>
<Div class = "txt-Example">
<Label for = ""> User Password/label>
<Input id = "new_password" name = "new_password" type = "password"/>
</Div> |
Note that the ajax operation is slightly different from other operations, but only in dataType: 'json'. Then we can use json. the content accessed in the form of mid is actually in the form of an array $ a ['a']. json is a returned array, and mid is the id we return.