日期:2014-05-16 浏览次数:20549 次
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function submitForm(){
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
url=encodeURI("index.php?txt="+document.forms.form1.input1.value);
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
alert('提交成功');
}
}
$.ajax({url:'index.php',data:$('表单选择器').serialize(),type:'POST',dataType:'html',success:function(data){
alert('提交成功!');
},error:function(xhr){
alert('动态页出错\n'+xhr.responseText)
}})
//无上传
$("#form1").submit(function(){
$.ajax($(this).attr('action'),$(this).serialize(),function(json){
//处理代码
},'json');
return false;
});
//有上传
$("#form1").ajaxSubmit({
dataType:'json',
success:function(json){
//处理代码
}
});