日期:2014-05-16  浏览次数:21952 次

我用$.ajax,被困了好几天啊。救命啊 - Web 开发 / Ajax
源码如下。
<form   name= "_LAF "   enctype= "multipart/form-data "   action= "/taicang/BCET.nsf/0/a9028adbf3e4f2cc482579810042232a?SaveDocument "   method= "post ">
<input   type=button   value= 'submit '   onclick= 'submitdoc(); '     />
<input   value= ' '   id= 'BSAction '   />
<script>
function   submitdoc(){
$id( 'BSAction ').value= 'DELETEFILE ';
var   f1   =   $( "form ");

var   msg= " ";
$.ajax({
            type:   "POST ",
            url:   f1.attr( 'action ')   ,
            data:   " ",
            success:   function(msg){
alert(msg);
},
            error:function(XMLHttpRequest,   textstatus,   errorthrown){
                alert( "error   :   "+textstatus+errorthrown+ ",   please   try   it   again ");
            }
});
}  

function   $id(id)   {
        return   document.getElementById(id);
}
</script>
</form>
我的问题是,这个post没有把我当前的页面post过去。也就是说BSAction还是空。
这个问题困了好几天啊。救命啊

------解决方案--------------------
f1.attr( 'action ') 说明f1是jquery得到的对象
var f1 = $( "#form "); f1要这样取


------解决方案--------------------
data:{
BSAction:BSAction
},
data里要有参数
------解决方案--------------------
lz你这里好像乱的还不少,修改了一下见下面, 注意需要juqery支持,在前面引入juqery库
HTML code

<form   name= "_LAF " id= "_LAF "   enctype= "multipart/form-data "   action= "/taicang/BCET.nsf/0/a9028adbf3e4f2cc482579810042232a?SaveDocument "   method= "post "> 
<input   type=button   value= 'submit '   onclick= 'submitdoc(); '     /> 
<input   value= ' '   id= 'BSAction '   /> 
<script language="javascript" type="text/javascript"> 
function   submitdoc(){ 
    //attend: need jquery support
    $('#BSAction ').val('DELETEFILE '); 
    //var   f1   =   $( "form ");     
    var   msg= " "; 
    $.ajax({ 
        type: "POST ", 
        url: $('#_LAF').attr( 'action '), 
        async: true,
        data: "", 
        success: function(re){ alert(re); }, 
        error:function(XMLHttpRequest, textstatus, errorthrown){ 
            alert( "error   :   "+textstatus+errorthrown+ ",   please   try   it   again "); 
        } 
    }); 
}   

//function   $id(id)   { 
//        return   document.getElementById(id); 
//} 

</script> 
</form>