English 中文(简体)
页: 1 ajax员额失败,但适当数据退还
原标题:jQuery ajax post failing, but proper data returned

我在座各位。 我试图做一个简单的jax表格,而回答是一滴错误。 然而,我的网页仍然显示我的神职人员的反应。 这里是我的支部:

$(function () {
    $( #searchForm ).submit(function () {
        var jqhxr = $.post({ url: this.action, type: this.method, data: $(this).serialize(), dataType:  json  })
                     .done(function () { alert( success ) })
                     .fail(function () { alert( fail ) })
                     .always(function () { alert( complete ) });
        return false;
    });
});

正在安排一个伙伴关系。 NET MVC page(尽管我不认为是问题);路线是正确的,被击中,回到了适当的数据,但情况是:

    [HttpPost]
    public JsonResult Search(SearchFormViewModel vm)
    {
        var products = _productRepo.Find(...);
        return Json(products);
    }

因此,情况是,表格按原样通过麻省提交,但我还是听不到警示,因此请求是成功的。 任何想法?

问题回答

这是黑暗的表象,但我想知道,这是否会做你想要做的事情。

   $(function () {
        var jqhxr;     
        $( #searchForm ).submit(function () {
            jqhxr = $.post({ url: this.action, 
                                type: this.method, 
                                data: $(this).serialize(), 
                                dataType:  json ,
                                success: function(data){ alert("success - data"); }
                        });                         
            jqhxr.done(function () { alert( success - done ) });
            jqhxr.fail(function () { alert( fail ) });
            jqhxr.always(function () { alert( complete ) });
            return false;
        });
    });

基本上,我在这里所做的一切都给它留下了成功。

替换<代码>$.post with .ajax:

$.ajax({    
    url: this.action, 
    type: this.method, 
    data: $(this).serialize(), 
    dataType:  json  }
)
.done(function () { alert( success ) })
.fail(function () { alert( fail ) })
.always(function () { alert( complete ) });




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签