I have the following json in one of the links:
{"edi":[{"NEdid":"19", "Publications":"B0001", "NCid":"141"
, "SEditionCode":"C0001", "SLang":"English", "STimeZone":"GMT+4:00"
, "SEdname":"Default", "NEdmon":"1", "NEdtue":"1", "NEdwed":"1"
, "NEdthu":"1", "NEdfri":"1", "NEdsat":"1", "NEdsun;":"1"
, "SFrequency":"Daily", "NSequence":"1", "dtCreatedOn":"2013-03-25 12:18:46.0"
, "NCreatedBy":"3", "dtModifiedOn":"2013-03-25 12:18:46.0"
, "NModifiedBy":"3", "BIsActive":"1", "BIsDeleted":"0", "NNoe":"7"}]}
I want to parse cross domain json. I am calling the following function on page load of a php page and using localhost. I am using the following code:
function loadEditionList(edurl) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var jsonEdition = xmlhttp.responseText;
var objEdition = JSON.parse(jsonEdition);
for (var i = 0; i < objEdition.edi.length; i++) {
var editionname=objEdition.edi[i].SEdname;
alert(editionname);
}
}
}
xmlhttp.open("GET", edurl, true);
xmlhttp.send();
}
Above code is working in IE with a alert message regarding security, but it is not working in chrome and mozilla. xmlhttp.status is 0 in chrome and mozilla.
Another code I used:
function loadEdition()
{
var getUrl = 'someurl/desktopReader.do?numPublisher=3&type=Editions&numPublication=19';
$.ajax({
url : getUrl,
type : 'GET',
dataType : 'jsonp',
jsonp: 'jsonp',
crossDomain : true,
success: function() { alert('Success!'); },
error: function() { alert('Uh Oh!'); },
});
}
In this case I always get alert 'Uh Oh!'.
Please, suggest me the proper way!