开发者

Making a GET request with jQuery like WGET

i want to call a webpage from jQuery and add the content to it to a div.

The downloaded data should not undergo any parsing, it should be in raw format.

I try to integrate the another application to my website.

I've done some experimenting and the code does a successful request, but

there seems there is no result displayed properly.

<html>
    <head>

    </head>


    <h1>Whisper</h1>

    <div id="result"></div>


    <h3>Output</h3>
    <div id="output"></div>


    <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="jquery.cookie.js"></script>
    <script type="text/javascript">

        $(document).ready(function() {

            $.ajax({

                type: "GET",
                // dataType: "script",

                url: 'http://somesite.com/ajax/开发者_StackOverflowchat.php?&test=1&l=1&tt=1',
                //data: "",
                beforeSend: function(){
                    // alert( "sending " );
                },
                error: function( request,error ){
                    alert("error: " + error + " " + request );
                },
                success: function(data, textStatus, XMLHttpRequest) {

                    $("#output").html( "output: " + data + "." );
                    $("#result").html( "ok " + data +" "+ textStatus +" "+ XMLHttpRequest);
                    return false;

                }

            });

        });

    </script>

</html>

Since the output will not be HTML, it should be displayed without processing.


You're trying to access a resource on a remote domain with an XmlHttpRequest, which is by default blocked for security reasons by the Same Origin Policy. You are indeed making the request, but your response will be null...that's what the SOP does, it's a rule the browser follows blocking any content from reaching your JavaScript.

There are 2 options here:

  • Access the data via JSONP which is allowed (it works in an entirely different way creating a <script> element and does a GET...which can only execute JavaScript). I'm no expert on the facebook API, I'm not sure if what you're after is even available this way.
  • Proxy the request through your own domain, however the user won't be logged in since you don't have their cookies when making the request (again, for obvious security reasons).


I may be missing something here, but it sounds like you're looking for the load method in jquery: http://api.jquery.com/load/


You can't make ajax requests to other domains. The only way to work around that would be JSONP, and that requires cooperation on the server side (i.e. facebook's side).


To integrate with facebook you'll need to use facebook API. They'll ban you otherwise.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜