Community

Unable to get JSONP Data from Views Dadatource with jQuery

Dear Commuity,

I used Drupal for a couple of websites recently, but I am a complete newbie to JSON-related topics. I got a question about how getting JSONP data from a view that I created, using Views Datasource. I used a jsonp prefix, because I plan to set up a cross domain request. The actual URL of my source is http://www.pascalfendrich.net/test/?q=jsontest and the code that is generated is the following:

myjsondata({"calendar":
[{"entry":
{"field_datum":"Do 22.11.2012",
"title":"Air",
"field_support":"Oval"}
},
{"entry":
{"field_datum":"So 25.11.2012",
"title":"S\u00e9bastien Tellier",
"field_support":"Orange"}
},
{"entry":
{"field_datum":"Do 22.11.2012",
"title":"Daft Punk",
"field_support":"Justice"}
}
]})

I use the following jQuery Script to get the data at http://www.pascalfendrich.net/jsontest :

$.getJSON('http://www.pascalfendrich.net/test/?q=jsontest?callback=myjsondata', function(data) {
      var items = [];
  var i = 0;
      $.each(data.calendar, function(key, val) {
            i = 0;
items.push('</li><li id="' + key + i + '">' + val.entry.field_datum + '</li>');
i++;
items.push('</li><li id="' + key + i + '">' + val.entry.title + '</li>');
i++;
items.push('</li><li id="' + key + i + '">' + val.entry.field_support + '</li>');
      });
      $('<ul>', {
            'class': 'event-calendar',
            html: items.join('')
      }).appendTo('body');
});

Nothing happens... Obviously something is wrong with my callback function. I tried hard to find out the correct synthax, but I did not find anything that helped me figure out, how it should be. The whole thing worked, as long as I was outputting normal JSON (not wrapperd in the myjsondata() function). The corresponding URL in the jQuery.getJson() function then was 'http://www.pascalfendrich.net/test/?q=jsontest'. This worked perfectly until I ported the request to another domain. I tried to append the correct string to the URL, like "?callback=?", "?callback=myjsondata", "?myjsondata=?" etc. ..., but as I don't really understand the syntax of this, I could not get it working. Can anyone help? This wold be greatly appreciated.

Thank you very much

nobody click here