Codigniter框架使用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>