weixin_33675507 2014-01-29 23:59 采纳率: 0%
浏览 85

Ajax serialize()表单错误

There have been similar questions, but I have browsed them a lot and found no accurate answer or fix so please offer a solution!

I am ajaxing a form to a page, and expecting a value back - no big deal. I've done it a million times before, but now it just refuses to work for this one form.

form html:

<form class="selectClaimType" action="place.php" method="post">
   <select id="claimtype" name="claimtype">
   <option value="privatebuilding">Private Building</option>
   <option value="communalbuilding">Communal Building</option>
   <option value="outside">Stored Outside</option>
   </select>
   <input type="submit" id="submit2" name="submit2" class="button" value="save"/>
</form>

jQuery:

$('form.selectClaimType').on('submit',function(e) {
    console.log('found');
    $form = $(this);
    console.log($form.serialize());
    e.preventDefault();
    $.ajax({
        url: "place.php", //$form.attr('action'),
        type: "post", //$form.attr('method'),
        data: $form.serialize(),
        success: function(data) {
            console.log(data);
            if (data == 1) {
                console.log('hello');
            }
            else {
                console.log('failure to change claim type'+data);
            }
        },
        data: function(data) {
            console.log('error ajaxing'+data);
        }
    });
});

The form is not dynamically created, and as you can see I have console.log(ged) nigh on everything. So I know that the form.serialize() is working (values appear as expected). I left out the preventDefault() to test, and the get values were correct. I have tried dataTypes of script, html, text, xml and json - no success.

I have a var_dump of $_REQUEST and $_POST on the posted to page - these are both empty arrays. I have changed the page that the post is sent to - still doesn't work.

Any ideas at all?

  • 写回答

3条回答 默认 最新

  • weixin_33719619 2014-01-30 00:02
    关注

    Maybe it is failing. Have you added a fail() callback to see if you get any output from that. Maybe the error is where you are submitting.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分