Reputation: 53
I want to pare the JSON URL data in HTML web page and display it on page,I am using following code.
I want to show JSON Data in paragraph div.
<script>
function gContent(){
alert('working');
$.getJSON('http://www.celeritas-solutions.com/pah_brd_v1/productivo/getGroups.php? organizationCode=att&userId1&', function(data) {
alert(data);
$(".paragraph").html(data);
});
}
</script>
Upvotes: 1
Views: 3002
Reputation: 3670
Origin null is not allowed by Access-Control-Allow-Origin.
This is the message one usually get when trying to get data from other websites/domains due to same origin policy. Inorder to overcome this problem we go for two major methods:
You can easily get your data using JSONP. If needed, you can use CORS, where you need that other website to allow your site in its headers.
In JSONP callback, one should be careful in the url you have given. That url where the callback value is present should not have any other elements except jsonp callback function. ie., first element of that page (even it should not have any html tags at first), should be jsonp callback function what you have given.
Upvotes: 1
Reputation:
By the same you tried and just adding $.each
using jQuery for getting each fieldData from the response.
<script>
function gContent(){
alert('working');
$.getJSON('http://www.celeritas-solutions.com/pah_brd_v1/productivo/getGroups.php?organizationCode=att&userId1&', function(data) {
$.each(data, function(i, fieldData){
$("p").append(fieldData + " "); //appending fieldDatas to paragraph tag
});
});
}
</script>
Upvotes: 1
Reputation: 11812
You can't call another domain using getJSON
you have to call the same domain. you can solve this by one of the following:
Access-Control-Allow-Origin
header JSONP
and add a callbackPHP
, you create a new page for example
calling_the_url.php
and you do file_get_contents('url');
and in your
javascript you call your calling_the_url.php
instead.Upvotes: 1
Reputation: 6544
You can use the JSON.stringify()
, to print the data as string to the DOM.
$(".paragraph").html(JSON.stringify(data));
check this http://jsfiddle.net/cc8HX/
Upvotes: 0