English 中文(简体)
页: 1 食堂
原标题:jQuery getJSON with mvc jsonresult

我有以下联合材料:

$( form ).live( submit , function (event) {

                    // Stop the form from doing a native postback
                    event.preventDefault();

                    $.ajax({
                        type:  POST ,
                        timeout: 5000,
                        url: $(this).attr( action ),
                        data: $( form ).serialize(),
                        success: function (responseHtml) {

                            $.getJSON($(this).attr( action ), function (data) {

                                console.log(data);

                            });

                        },
                        error: function (jqXHR, textStatus, errorThrown) {

                            alert( server error );

                        }
                    });
                });

谁应当将json从下列微粒方法中记录下来(,意思是一 log倒,而不是一ja误!):

 [HttpPost]
        public JsonResult Login(User user, string returnUrl)
        {
            // Validate the email and password
            if (users.Login(user.UserName, user.Password, Request.UserHostAddress))
            {
                FormsAuthentication.SetAuthCookie(user.UserName, true);

                // build redirectUrl ...
                //var redirUrl = ...
                return Json(new { uservalidated = true, url = false });
            }
            else
            {
                return Json (new { uservalidated = false, url = false });
            }
        }

如果我不同意联合材料,那么我会看到结果的罚款,但出于某种原因,联合材料会发现:

问题回答

认为你必须有Json RequestBehavior。 允许

return Json(....., JsonRequestBehavior.AllowGet);

此外:

如果你使用新闻 ChromeF12和网络,Pebug在Emland,看看你是否收到404、500或类似的错误,说明为什么没有发生。

您需要储存一个参考文件this,以促成关闭

$( form ).live( submit , function (event) {
        // Stop the form from doing a native postback
        event.preventDefault();
        var self = this; // add this so you have a reference to this in callbacks
        $.ajax({
            type:  POST ,
            timeout: 5000,
            url: $(this).attr( action ),
            data: $( form ).serialize(),
            success: function (responseHtml) {

                $.getJSON( $(self).attr( action ) , function (data) {

                    console.log(data);

                });

            },
            error: function (jqXHR, textStatus, errorThrown) {

                alert( server error );

            }
        });
    });




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签