0

I am trying to get the value from the serverside but i can't get it..Here, i am trying to convert the json data using JSON.parse(); but it is not working in jQuery... i don't know how to solve this...

    $(document).ready(function() {  
            $.ajax({    
                url:'http://newslet.comxa.com/NewsRecord.php' ,
                    dataType:'json',
                success:function(output_string) {
                    temp=JSON.parse(output_string);
                for(var i=0;i<temp.length;i++)
                {
                     $('#level').append('<div>Title &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:'+temp[i].Title+'<br>Source  &nbsp;&nbsp;&nbsp;:<a href='+temp[i].links+'>'+temp[i].Source+'</a><br>Category :'+temp[i].Category+'</div><hr>');
                 }                      
                }
             });
        });

i get this output when i am running these path 'http://newslet.comxa.com/NewsRecord.php'..

[{"Id":"2","Date":"","Title":"Hitachi Data Systems bets big on analytics","Source":"TOI","Category":"Corporate","links":"http:\/\/timesofindia.indiatimes.com\/tech\/tech-news\/software-services\/Hitachi-Data-Systems-bets-big-on-analytics\/articleshow\/26542988.cms?"},{"Id":"3","Date":"","Title":"British bike company Triumph drives into India","Source":"TOI","Category":"Industry","links":"http:\/\/timesofindia.indiatimes.com\/business\/india-business\/British-bike-company-Triumph-drives-into-India\/articleshow\/26542881.cms"}]
4
  • where have u declared var temp? Commented Dec 18, 2013 at 5:12
  • is there any error caught up in console? Commented Dec 18, 2013 at 5:13
  • try using this function $.each($.parseJSON(data), function(id, row) {}) Commented Dec 18, 2013 at 5:16
  • if i run using this $.each($.parseJSOn(data),fun) function i get this output in console....[10:51:18.859] The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. Commented Dec 18, 2013 at 5:22

2 Answers 2

1

you need to stringify first json result.

var json = JSON.stringify([{"Id":"2","Date":"","Title":"Hitachi Data Systems bets big on analytics","Source":"TOI","Category":"Corporate","links":"http:\/\/timesofindia.indiatimes.com\/tech\/tech-news\/software-services\/Hitachi-Data-Systems-bets-big-on-analytics\/articleshow\/26542988.cms?"},{"Id":"3","Date":"","Title":"British bike company Triumph drives into India","Source":"TOI","Category":"Industry","links":"http:\/\/timesofindia.indiatimes.com\/business\/india-business\/British-bike-company-Triumph-drives-into-India\/articleshow\/26542881.cms"}]);

var temp = JSON.parse(json);
Sign up to request clarification or add additional context in comments.

1 Comment

I think he doesnt even need to do this can loop through output_string only
0

Your string already is a valid json so there isnt any need to use

JSON.parse(output_string);

Check this fiddle http://jsfiddle.net/uDr6t/

3 Comments

i tried what u said but in that i got this console error...[11:10:26.222] SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data @ code.jquery.com/jquery-1.8.3.min.js:2
can u create fiddle for same
have u seen my fiddle?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.