代码如下:
$(document).ready(function(){
//alert("ok, guys.");
$("#addblog_form").submit(function(){return false;});
$("#s_btn").click(submitBlog);
});
function submitBlog()
{
var b = isInputRight();
if(!b)
{
alert("input is not correct.");
return;
}
//////////////////<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>
////// should be very carefull with the following line that you should have one space before the ":", or it won't work.
var data = $("#addblog_form :input").serializeArray();
//$.post($("#addblog_form").attr("action"), data, handleResp, "json");
$.ajax({
type: 'POST',
url: $("#addblog_form").attr("action"),
data: data,
success: handleResp,
error: handleErr,
dataType: 'json'
});
//alert("post go on ...");
}
function handleResp(json)
{
alert(json.message);
if(json.status == "fail")
{
}
else if(json.status == "success")
{
clearInput();
}
}
function handleErr()
{
alert("error when ajax.");
}
function clearInput()
{
$("#t_title").val("");
$("#t_blog").val("");
}
function isInputRight()
{
var title = $("#t_title").val();
if(title == "")
return false;
var blog = $("#t_blog").val();
if(blog == "")
return false;
return true;
}
标签:raw