dounan9070 2016-07-11 06:37
浏览 32

从PHP页面提交表单时不调用Ajax

HTML page

<form name="frm_add" id="frm_add" enctype="multipart/form-data">
    <input type="text" name="fname" id="fname" >
    <input type="file" name="img01" id="img01"> 
    <input type="submit" name="btn_submit" value="Add Data">
</form>

.js page

$(function() {
    $("#frm_add input, #frm_add select, #frm_add textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitSuccess: function($form, event) 
        {
            event.preventDefault(); 
            //alert("It's here 001");

            $.ajax({
                url: "./add_p.php",
                type: "POST",
                data: new FormData(this),
                dataType: "JSON",
                contentType: false,
                cache: false,
                processData:false,
            })
        },
    });
});

When I try to submit form, Ajax is not called on .js page and thus add_p.php is not called.

But if I declare action and method properties in form then add_p.php page is directly called and data are processed and inserted into database table without any issue.

<form name="frm_add" id="frm_add" action="add_p.php" method="post" enctype="multipart/form-data">

I checked all type of syntax and spelling errors but they seem ok and also read many things on internet but problem is still not resolved.

below alert is called if it is above Ajax but Ajax is not called.

alert("It's here 001"); 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 VMware 云桌面水印如何添加
    • ¥15 用ns3仿真出5G核心网网元
    • ¥15 matlab答疑 关于海上风电的爬坡事件检测
    • ¥88 python部署量化回测异常问题
    • ¥30 酬劳2w元求合作写文章
    • ¥15 在现有系统基础上增加功能
    • ¥15 远程桌面文档内容复制粘贴,格式会变化
    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”