Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json data cannot be read from web url

this link returns a json data set http://nutri.de.imerchmedia.com/services/accounts but everytime I use jquery to extract the data it doesnt show heres my code

$.getJSON( "http://nutri.de.imerchmedia.com/services/accounts", function(data ) {
$('#select').append("<option value='0' name='idsel'>Select Outlet</option>");
$.each(data, function (i, item) {
$('#select').append("<option value='" + item.outlet_group_id + "'>" +
item.outlet_group_name + " : " + item.outlet_group_code + "</option>");
});
});
<div id="content">
<?php
echo '<form method="POST">';
echo '<select id="select" name="id"></select>';
echo '<input type="submit" value="Submit" name="submit"/>';
echo '</form>';

if(isset($_POST['submit'])){
echo $_POST['id'];
}
?>
</div>
like image 489
A Super Awesome Avatar asked Feb 15 '26 21:02

A Super Awesome


1 Answers

That's an error, more specifically a same-origin error

http://jsfiddle.net/gyTjL/

// had to post some code
$.get('http://nutri.de.imerchmedia.com/services/accounts').fail(function(a,b,c) { 
    // gives -> is not allowed by Access-Control-Allow-Origin. 
});

You can not make ajax requests to domains other than your own, unless JSONP is used, which isn't really ajax, it inserts a script tags, but jQuery makes it look like ajax, or if the server you're contacting supports CORS.

Otherwise, the iteration seems to work -> http://jsfiddle.net/gyTjL/1/

like image 82
adeneo Avatar answered Feb 18 '26 11:02

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!