如何用JS从URL中获取内容?

我有个链接http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za-android/?json=get_all_posts

我想用JS从URL中获取内容。但我看到其中有些关于origin policy的东西。我需要那个吗?你能写一些小例子告诉我如何从这种类型的URL中获取内容吗?

Use jQuery:

$.ajax({
  type: 'GET',
  url: 'http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za-android/?json=get_all_posts',
  dataType: 'jsonp',
  success: function(data) {
    do_things(data);
  },
});

You can use getJSON from jQuery library: see here for more informations and parsed callback data.

$.getJSON("http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za-android/?json=get_all_posts", function( data ) {

  // parse your data
});

or:

$.ajax({
   url: "http://surfujpametno.roditelji.me/2014/01/23/surfujpametno-aplikacija-za-android/?json=get_all_posts",
   dataType: 'jsonp',
   success: function(data) {

      // parse your data
   },
});

If you need cross-origin request use jsonp parameter.

You can use JQuery's ajax with JSONP to get past origin policy problems

http://jsfiddle.net/Sam88/DkLUL/

$.ajax({
   type: 'GET',
   url: url,
   async: false,
   jsonpCallback: 'callback',
   dataType: 'jsonp',
   success: function(json) {
      console.log(json.status);
   },
   error: function(e) {
      console.log(e.message);
   }
});