weixin_33690367 2015-09-24 07:22 采纳率: 0%
浏览 87

不通过ajax请求

To send values to php through ajax ,i have created following functions in JS.

 function sendDataToServer(url,val)
    {
        var html='';
        html +='<div id="fakeDiv">';
        html +='<form action="'+url+'" method="get" enctype="multipart/form-data" id="fakefrm">';
        html +='<input type="hidden" name="jsvar" id="jsvar" value="'+val+'"/>';
        html +='</form>';
        html +='</div>';
        $('body').append(html);
        sendAjaxForm($('#fakeDiv'),function(){return true;},
function(){alert('done');$("#fakeDiv").remove();});
    }

sendAjaxForm

function sendAjaxForm(frm,callbackbefore,callbackdone)
{
    var form = frm;
    form.submit(function(event){
        event.preventDefault();
        var formData = new FormData(form);
        var ajaxReq=$.ajax({
            url: $(this).attr('action'),
            type: $(this).attr('method'),
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            beforeSend: function(){
                            callbackbefore();
                        }
            });

            ajaxReq.done(function(data){
                callbackdone(data);
            });
    }); // submit done
}

Then calling it on the page as

sendDataToServer("master.php?action=send_token","23x4dzy009r");

But no request is being made , as seen in console.. No any syntax error even recognised . What is wrong in this ??

  • 写回答

3条回答 默认 最新

  • weixin_33704234 2015-09-24 07:29
    关注

    You have passed #fakeDiv as your form, actually it should be #fakefrm.

    评论

报告相同问题?