【问题标题】:jquery $.post not working in the load callback function?jquery $.post 在加载回调函数中不起作用?
【发布时间】:2012-07-06 14:18:12
【问题描述】:

这是我的代码

$('#edit-popout-warpper').load(url,function(){
  //the url contain the editnameform
            $('#editnameform').submit(function(e){
                e.preventDefault(); 
                var $form = $( this ),
                    term = $form.find( 'input[name="mymoname"]' ).val(),
                    urll = $form.attr( 'action' );
                $.post(urll,{mymoname:term});

            })
        })
        return false;

在我使用 jquery ajax 加载方法后,$.post 不起作用,它没有发送 post 请求知道为什么吗?

我终于让它工作了,只是我像这样使用了 $.ajax

 $.ajax({
         type:'POST',
         url:urll,
         data:{mymoname:term}
       })

我不知道为什么。但至少它起作用了。所以任何人都知道为什么 $,post 不起作用请让我知道thanx

【问题讨论】:

  • 这个#editnameform 找到了吗?可以在回调函数的第一行尝试alert($('#editnameform').length);
  • 你能在jsFiddle复制它吗?
  • 你能检查开发者工具栏(通常是 F12)网络选项卡吗?您从请求中得到的错误代码是什么?标头也很方便。
  • 我在点击提交按钮后使用 firebug 没有任何反应,甚至没有错误消息

标签: jquery ajax post


【解决方案1】:

你错过了 post 回调函数。

$('#editnameform').submit(function (e) {
    e.preventDefault();
    var $form = $(this),
        term = $form.find('input[name="mymoname"]').val(),
        urll = $form.attr('action');
    $.post(urll, {
        mymoname: term
    }, function(data) {
       console.log(data);
    });
});

【讨论】:

  • @chenliang 所以问题是你错过了回调函数。
  • $.post 回调不是可选的吗?
  • @chenliang 你怎么知道你的$.post 不起作用?你检查http请求和响应了吗??
  • 我使用了萤火虫,控制台不显示发布请求;并且我的数据库没有更新,当我使用正常的方式提交它工作的表单并且有一个发布请求时
猜你喜欢
  • 2013-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 1970-01-01
  • 2012-11-12
相关资源
最近更新 更多