3

I am not getting any response from server with following code ,I am getting token error '<' i have tried all

$(document).ready(function() {
    $.ajax({
        url:"url", 
        dataType: 'json',
        success: function(output) {
            var asd = JSON.stringify(output)
            var i = $.parseJSON(asd);
            for(var j=0;j<i.length;j++) {
                $('#one').append('<p><div>TITLE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp&nbsp: &nbsp; &nbsp;<a href='+i[j].links+'>'+i[j].Title+'</a><br>SOURCE&nbsp; &nbsp;&nbsp;&nbsp; :  &nbsp; &nbsp;'+i[j].Source+'<br>CATEGORY&nbsp;: &nbsp; &nbsp;'+i[j].Category+'<hr></p></div>');
                //$('#one').append('<p><div style="background-color:#ccc"><span style="font-weight:bold" >SOURCE</span> &nbsp; &nbsp;&nbsp;&nbsp; :  &nbsp; &nbsp;'+i[j].Source+'<p>');
                //$('#one').append('<p><div style="background-color:#ccc" onclick="get"><span style="font-weight:bold" >CATEGORY</span> &nbsp;: &nbsp; &nbsp;'+i[j].Category+'<hr><p></div>');

            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(xhr.statusText);
            alert(thrownError);
        }
    });
});

1 Answer 1

2

There is no need to call JSON.stringify() and parseJSON(). If output is an array, you can use directly output[0].Source and output[0].Category

$.ajax({
url:"url", 
dataType: 'json' ,

success:function(output) {
    for(var j=0;j<output.length;j++) {
        $('#one').append('<p><div>TITLE&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp&nbsp: &nbsp; &nbsp;<a href='+output[j].links+'>'+output[j].Title+'</a><br>SOURCE&nbsp; &nbsp;&nbsp;&nbsp; :  &nbsp; &nbsp;'+output[j].Source+'<br>CATEGORY&nbsp;: &nbsp; &nbsp;'+output[j].Category+'<hr></p></div>');
    }
},
error:function(xhr,ajaxOptions,thrownError){
    alert(xhr.statusText);
    alert(thrownError);
}
});
Sign up to request clarification or add additional context in comments.

5 Comments

it returns unexpected token < in alert box
@user2992174 can you post raw response from server here?
syntax Error:Unexpected token <
@user2992174 ok, I sent this request by myself. Server also anwers some commentaries at the end of data: <!-- Hosting24 Analytics Code --> <script type="text/javascript" src="stats.hosting24.com/count.php"></script> <!-- End Of Analytics Code --> You should remove this
@user2992174 Server should not answer any comments, only data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.