Hi everyone,
i have a page that uses jquery ajax to get json from another page. However, instead of the ajax using sucess, it goes directly to error. I have a debug on the error to see what is the issue and i get "Parsing JSON Request failed."
page 1.php
$("#validate").click(function() {
var tags = $("#coc_tag").val();
var type = $("#type").val();
var cleantag = tags.replace(/#/, "%23");
switch(type) {
case 'clan':
$.ajax({
url: "/coc/mirror.php?tag="+cleantag+"&type="+type,
method: "GET",
//dataType: "json",
cache: false,
success: function(data, textStatus){
//for testing.
alert("good");
$.each(data,function( key, value ) {
alert( key + ": " + value );
})
},
error:function(x,e) {
if (x.status==0) {
alert('You are offline!!\n Please Check Your Network.');
} else if(x.status==404) {
alert('Requested URL not found.');
} else if(x.status==500) {
alert('Internel Server Error.');
} else if(e=='parsererror') {
alert('Error.\nParsing JSON Request failed.');
} else if(e=='timeout'){
alert('Request Time out.');
} else {
alert('Unknow Error.\n'+x.responseText);
}
}
});
break;
}
});
here is the php page the outputs the json.
mirror.php
<?php
header('Content-type: application/json');
// extra curl stuff that i took out
$headr = array();
$headr[] = "Accept: application/json";
$headr[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$data = json_decode($res, true);
$items = $data["items"];
class item {
public $tag = "";
}
$test = new item();
foreach($items as $item) {
$test->tag = $item["tag"];
echo json_encode($test);
}
curl_close($ch);
?>
The output looks like this
{"tag":"#VGLVGVVJ"}{"tag":"#Y0G8PC2G"}{"tag":"#90UVCJUU"}{"tag":"#LG9L8GJG"}{"tag":"#J80R2VLJ"}{"tag":"#9PP298LR"}{"tag":"#Q0JYV8JU"}{"tag":"#9JY2U2YY"}{"tag":"#LPUUG2Y9"}{"tag":"#GL9929UC"}{"tag":"#PG0QQJ09"}{"tag":"#9PLR09G0"}{"tag":"#GCJPQ92Y"}{"tag":"#UC00RCLJ"}{"tag":"#2LR8UVLJ0"}{"tag":"#RVUYGCPV"}{"tag":"#2LJLQGYGG"}{"tag":"#RQ22PJYC"}{"tag":"#PP0P9VUL"}{"tag":"#8RVCV0RV"}{"tag":"#QL88L9CJ"}{"tag":"#RUCLLUV"}{"tag":"#2Q0PQCPV"}{"tag":"#RYLJJU02"}{"tag":"#GVGJLQU9"}{"tag":"#L8VLQGC9"}{"tag":"#2288P98Q8"}{"tag":"#2CG22U002"}{"tag":"#VGJQYQQ9"}{"tag":"#2ULCPY2G0"}{"tag":"#229GP9C09"}{"tag":"#82RPULG2"}{"tag":"#VU82QUCY"}{"tag":"#202JCRL9"}{"tag":"#VCR8PY2V"}{"tag":"#8YLC2LJCR"}{"tag":"#GUQJQU90"}{"tag":"#RPQ0U2Y0"}{"tag":"#2LLGC8C8V"}{"tag":"#22CPJRPPQ"}{"tag":"#UCUL0RR0"}{"tag":"#2LC82CL8"}{"tag":"#2RJQ9P28C"}{"tag":"#2QPCYY9U"}{"tag":"#P2VU8YG0"}{"tag":"#20RGCLCL"}{"tag":"#2YJG2R88C"}
Again, im getting the error trigger on the jQuery ajax.