jquery ajaxt提交在firefox,chrome下遇到的问题

var str = $('#f1').formSerialize();

$.ajax({
type:'post',
url:'actionHRDemand.php',
data:str,
dataType:'json',
error:function(XMLHttpRequest, textStatus, errorThrown){
                        alert(XMLHttpRequest.status+","+XMLHttpRequest.readyState+","+textStatus+","+errorThrown);                        
},
success:function(result){
if(result['num']==1){
jQuery("#jqgrid").trigger("reloadGrid")
}else{
alert('操作失敗');
}
}
});

以上代码在IE6.0中无问题,在firefox,chrome中,无法提交,页面重新加载了.用firebug调试可以看到str数据post到了当前页面,后台保存

失败.也就是说没有请求url:'actionHRDemand.php',而是请求的自身页面.百思不得其解.后尝试将async:false,数据可以提交后台保存,

但是当前页面任然重新加载.

我的form是这样的:<form name="f1" id="f1" action="" method="post" enctype="application/x-www-form-urlencoded">

如果在action中写入'actionHRDemand.php,页面则会跳转到'actionHRDemand.php页面.

我在当前页面中还使用了jqgrid插件,在加载时请求数据,是没有问题的但是执行以下代码:

 

//查询

function query(){

        var accountid = $("#accountid").val(); 

        var departid = $("#departid").val(); 

        var proposerid = $('#proposerid').val();

        var demandtime = $('#demandtime').val();

        var position = $('#position').val();

        var howmany = $('#howmany').val();

        var matter = $('#matter').val();

 

        if(isNaN(howmany)){

alert("請輸入正確的需求人數");

return;

}

       $("#jqgrid").jqGrid('setGridParam',{ 

            url:'actionHRDemand.php?op=grid',     postData:{'accountid':accountid,'departid':departid,'proposerid':proposerid,'demandtime':demandtime,'position':position,'howmany':howmany,'matter':matter}, 

            page:1

        }).trigger("reloadGrid");

}

发生了同上面一样的问题,页面重载了.

似乎$(function(){});以外的ajax请求全都出问题了.

 

这个问题已经困扰了我好久,特地发出来请广大网友指点.

请检查button是否用成submit button了。

$.ajax({
type:'post',
url:'actionHRDemand.php',

data:str,

改成
$.ajax({
type:'post',
url:'actionHRDemand.php?'+str,

试试呢 你firebug看看请求参数传递了吗 响应是什么

估计是你触发事件的这个按钮的问题,是a标签?button还是submit?

button是否写在form外面。写里面有这种情况出现。