开发者

Why does my Ajax success function never trigger?

My $.ajax success function never 开发者_高级运维triggers. I just want to execute a PHP file without passing and getting ANY values. I am using another way of reading values, but it can't be run since the function needs to be put in the $.ajax success function, which does not work.

Code:

$(document).ready
(
    function()
    {
        var interval;

        function ajaxify()
        {
            $.ajax
            (
                {
                    url:"http://localhost/twitter/redirectFollow.php",
                    success:function()
                    {
                        $("#resultPara").prepend("test123"); // This does not trigger
                    }
                }
            );  //  End $.ajax
        }   //  End ajaxify

        $("#buttonClick").click
        (
            function()
            {
                ajaxify();
            }
        );  //  End buttonClick
    }
);


Use Firebug or equivalent tool to ensure the request is being made successfully and that you are receiving a response.

My guess would be that since you are specifying an absolute url, the request is being seen as a cross-domain request. If the script you are requesting resides on the same domain the javascript is on, shorten the url to /twitter/redirectFollow.php, otherwise you will have to use a data-type of JSONP. See docs


This is obviously a problem in your ajax request, your request is not successful, hence no call to success.

Your code works just fine in the jsfiddle here: http://jsfiddle.net/Sgbup/ (with the ajax echo service)

check the calls with firebug or with chrome's javascript console.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜