开发者

Sending GET to server gives no response (but status returned)

开发者 https://www.devze.com 2023-01-27 11:22 出处:网络
I\'m sending an ajax request to my server that updates some data there. Request is sent with jquery\'s get function. On success I\'d like te perform some action, but unfortunately whole operation fail

I'm sending an ajax request to my server that updates some data there. Request is sent with jquery's get function. On success I'd like te perform some action, but unfortunately whole operation fails since server gives no response, even though firebug clearly shows 200 status:

Sending GET to server gives no response (but status returned)

What more, when I enter this address with browser, also everything looks fine. Any ideas why it may not be working properly ? Here's my js:

    $(".interests-delete").live("click", function(){
        var id = $(this).attr('title');
        var user_id = "100000717262400";

        $.ajax({
            type: "GET",
            url: "http://dev1.gecoloco.com/rte/ilike.php?",
            data: "u=" + user_id + "&d开发者_C百科=" + id,
            dataType: "json",
            success: function(response, status){
                alert(status);
                console.log(response);
                getLikes();
            }
        });
        return false;            
    });


It's very likely due to "same origin policy' which mandates your html should come from the same domain to which ajax call is issued. Try loading your html page not from file system but through the same server serving the ajax calls. It will work.


Your url looks a bit funny there. The part: "?&u=..." should be "?u=..."


Maybe something is wrong with your success function. It is possible you are getting a response but your javascript is crashing somewhere in your function.


I've experienced this before when I opened a page from the local file system in my browser, e.g. file:///C:/Users/Eason/Desktop/mailer/index.html.

When this page attempts to make an AJAX request, it would cause that problem. When it's published on a web server (e.g. Tomcat) it would work.

This is a security restriction in the browser to prevent unsafe cross-domain traffic.

0

精彩评论

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

关注公众号