<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ci ajax demo</title>
<script type="text/javascript" src="<?php echo base_url().'admincp/'.setting('backend_theme').'/'; ?>js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
$("#login_submit").click(function(){
var username = $("#username").val();
var password = $("#password").val();
$.ajax({
type: 'post',
//dataType: 'json',
//cache: false,
//url: " http://127.0.0.1:81/admincp/default/test_types_ajax.php",//这个可以得到返回值
url: "<?php echo site_url('admin/test/post_action'); ?>",//这个没法得到返回值
data: 'username=' + username + '&password=' + password,
success:
function(msg){
alert("ok");
$("#form_message").html(msg.message).css({"background-color": msg.bg_color}).fadeIn('slow');
},
error: function() {alert("ajax error");}
});
return false;
});
});
</script>
<style type="text/css">
body{
background-color: #fff;
margin: 40px;
font-family:Arial, Helvetica, sans-serif;
font-size: 14px;
color: #4f5155;
}
a{
color: #003399;
background-color:transparent;
font-weight:normal;
}
h1{
color: #444;
background-color:transparent;
border-bottom:1px solid #d0d0d0;
font-size:16px;
font-weight:bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}
code{
font-family:Monaco, Verdana, Arial;
font-size:12px;
background-color:#f9f9f9;
border:1px solid #d0d0d0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#form_message{
display:none;
text-align:center;
margin-bottom:5px;
padding:10px;
}
</style>
</head>
<body>
<h1>This is the demo page ofr the simple AJAX post in CodeIgniter Using jQuery</h1>
<p>Username: stamhe | Password: 123456</p>
<p>
Try to enter nothing in the fields and click the submit button.<br/>
Try to mismatch the username and/or password and click the submit button.
</p>
<div style="text-align:right; width:500px;">
<div id="form_message"></div>
<form name="ajax_form" id="ajax_form" method="post">
Username/Email:*<input type="text" name="username" id="username" size="30" /><br/><br/>
Password:*<input type="password" name="password" id="password" size="30" /><br/><br/>
<input type="submit" value="Submit" name="login_submit" id="login_submit" />
</form>
</div>
</body>
</html>