1

I'm simple trying to get the message from http://bootcamp.jit.su/welcome/marian

Here is the code i'm using

<!DOCTYPE html>
<html>
    <head>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <meta charset="utf-8" />
        <title>Globant :: Welcome to the HTML5 bootcamp</title>
    </head>
    <body>

    </body>
        <script type="text/javascript">
        $(document).ready(function(){
            var URL = "http://bootcamp.jit.su/Welcome/marian?callback=?";
            var request = jQuery.noConflict().ajax({
                    url: URL,
                    type: "GET",
                    dataType: 'jsonp',
                    processData: false,
                    success: function(data) {alert('hola') ;}
            });
        });

    </script>

</html>

It seems that it should work fine, but i keep getting an error message in the console : "unexpected ':' character"

j0k
  • 22,600
  • 28
  • 79
  • 90
Paranoid42
  • 118
  • 7
  • 1
    "var data = {message: 'message'}; data" seems unnecessary, try removing it and seeing if you still get the error. – mr_lewjam Nov 13 '12 at 09:19
  • the var data doesn't do nothing lol just ignore it – Paranoid42 Nov 13 '12 at 09:26
  • so if it isn't jsonp i can't get it? – Paranoid42 Nov 13 '12 at 09:27
  • yes, when the service doesn't support jsonp you can't get the response with your script. – Dr.Molle Nov 13 '12 at 09:29
  • **I wrote an answer related to this question here: [Loading cross domain html page with jQuery AJAX](http://stackoverflow.com/questions/15005500/loading-cross-domain-html-page-with-jquery-ajax/17299796#17299796)** – _the last one, supports https_ – jherax Jun 26 '14 at 16:47

1 Answers1

1

The thing is JSONP is not an actual AJAX request. It is a workaround to trick browser and it is working by inserting a script tag to header. Think, this your JSONP supported URL

domain.com/jsonp.aspx?callback=processJSONP

the processJSONP is a function you already have in your page and the requests return a script similar to this

processJSONP( {
    "glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
});

it calls your function with the data you need and you do what ever you want to do. of course the data don't have to be a JSON object or you can get more callback like

processJSONP("data1=11");
processJSONP("data2=22");
processJSONP("data3=33");

So you cannot get the data you need if the URL doesn t support.

To achieve what you want here you have to use a server side script (e.g. ASP.Net, PHP etc) and Request the content by a server side object (WebRequest, HttpRequest) and when you get it just you can use it as a JSONP or standard AJAX request as it is in your own domain right now.

Hope this clears everything.

Onur Topal
  • 3,042
  • 1
  • 24
  • 41