javascript - ajax 使用 php 提交无刷新表单

标签 javascript php jquery ajax forms

好的,所以我知道这个 ajax 有效,但我似乎无法理解为什么它不在此处提交。

<script type="text/javascript">
$(function(){
    $('input[type=submit]').click(function(){
        $.ajax({
            type: "POST",
            url: "postitem.php",
            data: $("#myform").serialize(),
            beforeSend: function(){
                $('#result').html('<img src="loading.gif" />');
            },
            success: function(data){
                $('#result').html(data);
            }
        });
    });
});

提交表格

<form action="" method="post" onsubmit="return false;" id="myform">

提交按钮

<input type="hidden" value="Post" name="submit" /> 
<button type="submit" title="Done" style="height:33px; width:50px">
    <img src="../../css/images/plus_25.png" />
</button>

我觉得这个按钮有点问题,但我想保持按钮的原样,因为我的很多其他表单都使用这个相同的按钮,如果你能向我解释为什么点击这个提交按钮什么都不做,谢谢。

最佳答案

您正在选择 <input>而不是 <button> .我通过更改您的 jQuery 选择器获得了成功:

$('input[type=submit]')

为此:

$('button[type=submit]')

http://jsfiddle.net/H3Bcc/

关于javascript - ajax 使用 php 提交无刷新表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20385253/

相关文章:

php - 在 mysql 中插入类似的值,但使用单个查询多次更改日期列

php全局变量修饰符不起作用

php - 将多个php表单数组插入mysql行

javascript - 用链接替换标签,它只替换字符串中的最后一个词

JavaScript SVG 错误

javascript - JSON 解析与否?

javascript - 寻找光滑 slider 容器高度的问题

javascript - 过滤AngularJS中的数组值

c# - 如何更新动态生成的 asp :image in an UpdatePanel without flickering?

javascript - 创建一个包含滑动图像的 div