views:

52

answers:

4

Hello Friends,

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/chat.php?&amp;test=1&amp;l=1&amp;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.

A: 

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

eruss
Hello eruss, thank you for your kind answer. Unfortunately .load let's you only load from the same server. I need to pull the data directly from facebook. Did the example code work for you?
Herr Kaleun
@Herr - You *can't* load from another server, it's banned for security reasons, this applies to all XmlHttpRequests.
Nick Craver
A: 

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).

Thomas
A: 

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

cheshire
+1  A: 

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).
Nick Craver