The Codigniter framework uses jquery + ajax/"target =" _ blank "> The jquery ajax code is as follows:
| The code is as follows: |
Copy code |
|
<Form action = "<? Php echo @ htmlspecialchars ($ url ['login _ url'])?> "Method =" post "enctype =" application/x-www-form-urlencoded "name =" form1 "id =" form1 ">
<P> <label> salary: </label>
<Input name = "Login. Token1" class = "text" type = "text" id = "token1"/>
</P>
<P> <label> Password: </label>
<Input name = "Login. Token2" class = "text" type = "password" id = "token2"/>
</P>
<P>
<Input name = "login" type = "submit" id = "user_login" value = "login"/>
<Input type = "reset" value = "reset"/>
</P>
<B style = "color: red"> <? Php echo $ this-> session-> flashdata ('error');?> </B>
</Form>
<Script>
$ (Function (){
$ ("# User_login"). click (function (){
Var username = $ ("# token1"). val ();
Var salary_no = $ ("# token2"). val ();
$. Ajax ({
Type: "POST ",
Data: "username =" + username + "& salary_no =" + salary_no,
Url: "<? Php echo site_url ('Home/ajax_check_username ')?> ",
DataType: "text ",
Cache: false,
Error: function () {alert ('error ');},
Success: function (data ){
If (data = 'yes '){
Location. href = "<? Php echo site_url ('Home/index')?> ";
} Else {
Form1.submit ();
}
}
});
Return false;
});
});
</Script> |
Ajax submits the code to the home controller:
| The code is as follows: |
Copy code |
|
# Submit to local
Function ajax_check_username (){
// Redirect ('Home/index ');
$ Username = $ this-> input-> post ("username ");
$ Salary_no = $ this-> input-> post ("salary_no ");
If ($ this-> user_mdl-> check_ajax_user ($ username, $ salary_no )){
$ This-> session-> set_userdata ('salary _ no', $ salary_no );
$ This-> session-> set_userdata ('username', $ username );
Echo "yes ";
} Else {
Echo "no ";
}
}
|