0

I have a problem. I am a beginer.I am curently struggling with get and print (or show in alert) data from another webside.

Am I on a good way?

$.ajax({
    url: "http://www.ogimet.com/cgi-bin/getsynop?begin=201511201200&state=Pol&lang=eng&block=12100",
    type: 'GET',
    success: function(res) {
        var text = res.responseText;
    }
});
alert(text);

Any idea? Ogimet provides a SYNOP data. Than I will want to parse it, but now Iam doing something wrong cos I cant get this data.

Edyta B
  • 29
  • 4

1 Answers1

0

jQuery ajax is asynchronous function call,

so your alert code will be in callback function.

$.ajax({
    url: "http://www.ogimet.com/cgi-bin/getsynop?begin=201511201200&state=Pol&lang=eng&block=12100",
    type: 'GET',
    success: function(res) {
        console.log(res);
        // var text = res.responseText;
        // alert(text);
    }
});
Scarecrow
  • 4,057
  • 3
  • 30
  • 56
  • Ok, thank you. It is one step foward, now I can get alert, but it is empty. – Edyta B Dec 15 '15 at 18:55
  • @EdytaB try console.log(res) instead of alert and see the ourput in console – Scarecrow Dec 15 '15 at 18:58
  • it looks like something is going on!:) Now I've obtained massage: XMLHttpRequest cannot load file:///C:/Users/Edyta/Desktop/HTML/www.ogimet.com/cgi-bin/getsynop?begin=201511201200&state=Pol&lang=eng&block=12100. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.send @ jquery.js:9664 – Edyta B Dec 15 '15 at 19:32
  • its because of google chrome? – Edyta B Dec 15 '15 at 19:33