本文章结合Codigniter框架与jquery 的ajax实现PHP POST提交到两个地址实现代码,有需要了解的朋友可进入参考。
Codgniter框架使用jquery ajax/" target="_blank">jquery ajax代码如下:
代码如下
复制代码 |
代码如下 |
复制代码 |
<form action="<?php echo @htmlspecialchars($url['login_url']) ?>" method="post" enctype="application/x-www-form-urlencoded" name="form1" id="form1"> <p><label>工资号:</label> <input name="Login.Token1" class="text" type="text" id="token1" /> </p> <p><label>密 码:</label> <input name="Login.Token2" class="text" type="password" id="token2" /> </p> <p> <input name="登录" type="submit" id="user_login" value="登录" /> <input type="reset" value="重置" /> </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('http://pic4.phprm.com/2013/05/07/ajax_check_username.jpg')?>", dataType: "text", cache: false, error: function(){alert('error');}, success: function(data){ if(data == 'yes'){ location.href="<?php echo site_url('http://pic4.phprm.com/2013/05/07/index.jpg')?>"; }else{ form1.submit(); } } }); return false; }); }); </script> |
|
表>ajax提交到home控制器代码:
代码如下
代码如下 |
复制代码 |
#提交到本地 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"; } }
|
|
复制代码
|
|
# 提交到本地
function ajax_check_username(){
//redirect('home/index'); $username = $this- >input->post("用户名"); $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', $用户名); echo "是";
}else{ echo "否"; } }
论文地址:转载方便,但请附上文章地址:-)