开发者

Making jquery.get a jquery.ajax - not working?

开发者 https://www.devze.com 2023-04-06 08:58 出处:网络
I want to be able to show a loading div when making ajax requests, so I am trying to change my requests from $.get to $.ajax so I can use the beforeSubmit and complete actions.

I want to be able to show a loading div when making ajax requests, so I am trying to change my requests from $.get to $.ajax so I can use the beforeSubmit and complete actions.

F开发者_如何学Cor some reason, the get below works, but the ajax does not. Any thoughts as to why? The method is triggered, but in fiddler I can see no request goes back to the server.

WORKS:

$("#testBoundChart").click(function (e) {
                        $.get('/charter/bound', callbackFn);
                        function callbackFn(data) {
                            //Append markup to dom
                            $('body').append(data);
                            // call the js function from the partialview here 
                            generateChart();
                        }
                    });

NO REQUEST SENT:

            $("#testBoundChart").click(function (e) {
            alert("triggered");
            $.ajax({
                    url: '/charter/bound',
                    data: data,
                    success: (function(data) {
                        //Append markup to dom
                        alert("success");
                        $('body').append(data);
                        // call the js function from the partialview here 
                        generateChart();
                    }),
                    error: (function () {
                    alert("error");
                })
            });
        });

Many thanks


It looks like you are missing a semicolon for the error function. Though I'm not sure why it isn't giving a Javascript error.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号