I've been looking around stackoverflow for the answer to my problem but I can't seem to find why this is happening.
I've created a webserver which returns a JSON object:
http://213.125.101.19/api.php?function=test
After that i created an HTML file with the following javascript to call the JSON using Ajax
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxCall(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var response = ajaxRequest.responseText;
obj = JSON.parse(response);
console.log(obj);
if(response.indexOf("Fatal error")>=0){
alert('Error, Try again.');
}else{
document.getElementById("response").value = response;
}
}
}
ajaxRequest.open("GET", "http://213.125.101.19/api.php?function=test", true);
ajaxRequest.send(null);
}
</script>
When I run this code, my Firebug returns
"SyntaxError: JSON.parse: unexpected end of data obj = JSON.parse(response);"
If I run my JSON trough a validator, everything seems to be fine.
Any ideas how to fix this?
Kind Regards, Luuk