开发者

Why does my Ajax success function never trigger?

开发者 https://www.devze.com 2023-03-12 09:22 出处:网络
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

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

精彩评论

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

关注公众号