Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
        }
    });
});
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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);
}
});
share|improve this answer
 
@user2992174 see my edited answer –  Natalia Dec 18 '13 at 6:20
 
it returns unexpected token < in alert box –  vinodkumar Dec 18 '13 at 6:23
 
@user2992174 can you post raw response from server here? –  Natalia Dec 18 '13 at 6:25
 
syntax Error:Unexpected token < –  vinodkumar Dec 18 '13 at 6:29
 
@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 –  Natalia Dec 18 '13 at 7:37
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.