开发者

How to do a simple http get ajax style using mootools 1.2.1

I'm trying to do a simple ajax GET that returns the html from google.com but with the following I keep hitting my onFailure. And when I hit status i get a 0, yet when I attempt to output the responseText I get nothing.

Anyone done a simple request like this in mootools 1.2.1?

function addSomeAction() {
                        el.onclick = function() {
                        var uri = "http://www.google.com";

                                            var myRequest = new Request({
                                                url: uri,
                                                method: 'get',
                                                onRequest: function(){
                                                    alert("loading...");
                                                },
                                                onSuccess: function(responseText){
                        开发者_高级运维                            alert("hi");
                                                },
                                                onFailure: function(responseFail){
                                                    alert("fail: " + responseFail.responseText);
                                                }
                                            });

                                            myRequest.send();
                        }
                    }


Regardless of the framework used, you cannot do cross-domain AJAX requests. This is to prevent Cross-Site Request Forgery (CSRF) attacks and is a limitation imposed by the web browser.

Therefore, you can only fetch the HTML source of a page which on the same domain as the originating request.

There are specifications allowing for the asynchronous transfer of JSON data residing on another domain (JSONP), but they will not help you in this case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜