0

In my localhost, I create an web application to get data from website, it just contain one character. So I create this:

$.get("http://www.website.web.id/data.txt", function(client_req) { 
alert(client_req); 
});

But it can't load the data. Why?

rezafahlevi08
  • 347
  • 1
  • 5
  • 10

2 Answers2

3

Yes, cross domain issue, you can use JSONP or CORS to overcome this issue, I have posted multiple times on this:

JQuery JSON Calls To PHP WebService Always Runs "Error" Callback

Is there any physical, readable difference between a JSON string and a JSONP string?

Community
  • 1
  • 1
T McKeown
  • 12,971
  • 1
  • 25
  • 32
1

This may be a solution for you. See:

crossdomain.xml for jQuery?

I'd advise using JSON for this though -- I know it may not sound like a quick and easy solution, but it's the best solution.

If you're using PHP, you could do something like this:

<?php
   $arr = array('example' => 'example data', 'anotherexample' => 'OK', 'userage' => 13);
   echo json_encode($arr);
?>

That'd get it to output the data in JSON. Then in your jQuery, you'd do something like:

$.getJSON('http://www.website.web.id/data.php', function(client_req) {
        alert(client_req.example);
        alert(client_req.anotherexample);
        alert(client_req.userage);
    }
});

Hope that puts you in the right direction.

Community
  • 1
  • 1
Don Cullen
  • 403
  • 1
  • 4
  • 21