Hi guys,
I'm looking for some help to integrate data from Views3 in JqueryMobile framework via JSON.
I'm not able to display the Drupal data outside of its domain for some strange reason. I can get data on JSON from flickr, weather, and so on but not my drupal ! :-(
My script is running well with the JSON file stored locally (on the same domain) but I can't get it worked on remote access.

On the Drupal 7 side, I've installed : Services 3 and services_views module, which provide me JSON data:

http://www.example.com/portfolio.json

{
    "portfolio": [
        {
            "realisation": {
                "entity_id": "http://www.example.com/20-%202011%2010.png",
                "title": "site 1",
                "entity_id_3": "http://www.example.com"
            }
        },
        {
            "realisation": {
                "entity_id": "http://www.example.com/20-%202011%2010.png",
                "title": "site 2",
                "entity_id_3": "http://www.example.com"
            }
        }
    ]
}

And my other domain - http://m.example.com , I've :

...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function(){
	
	$.ajax({
		//url: 'zzzz_portfolio.json?callback=handle_data',  // this one is working ... 
		url: 'http://www.example.com/portfolio.json?callback=?',  //this not ! Why ???
		type: 'GET',		
		dataType : "json",
		timeout : 10000,
		crossDomain: true,
		success: function(data, status)
	   {
		    //alert(data.portfolio);
		   	$.each(data.portfolio, function(i,item){
  				//alert(i + item.realisation.title);
				content = '<li>'
						+ '<img src="' + item.realisation.entity_id + '" width="80" height="80" alt="' + item.realisation.title + '" />'
						+ '<h3>' + item.realisation.title + '</h3>'
						+ '<p>bla bla bla</p>'
						+ '<\/a>'
						+ '<a href="' + item.realisation.entity_id_3 + '" target="_blank" rel="external">' 
						+ item.realisation.entity_id_3 + '</a>'
						+ '</li>';
			
				$(content).appendTo("#posts");
				
         	});
	   },
	  error: function (xhr, ajaxOptions, thrownError) { 
                   alert(xhr.statusText); alert(thrownError); 
                   }
	});
});
</script>
</head>
<body>
 <h2>below some web design :</h2>
 <div id="posts"> HERE THE RESULT ...</div>
...
 

Any idea ?

Comments

ygerasimov’s picture

Can you inspect with firebug what is the response from drupal to your javascript?

Also make sure that you receive json data from services by anonymous user as javascript will act as anonymous with code above.

jim005’s picture

thanks for this tip, but I've already tried it :-) . I think the json data is ok.
I suspect something between, like cross-domain issue, json(p?) format error, ... but I can't find it !

ygerasimov’s picture

Could you please post here json response of your services call? I would like to take a look at it.

jim005’s picture

thanks by advance... here it the json response : http://www.example.com/portfolio.json

SilviaT’s picture

Got the same problem.
After many tries I managed to make it work by calling a random callback function.

Try

url: 'http://www.websenso.com/portfolio.json?callback=foo',
instead of
url: 'http://www.websenso.com/portfolio.json?callback=?',

and

dataType : "jsonp",
instead of
dataType : "json",

Hope this helps.

kylebrowning’s picture

Status: Active » Closed (works as designed)

You need to use JSONP for cross domain requests.

jim005’s picture

Issue summary: View changes