0

Main.js

$(function(){ 
   $.ajax({
      type: "GET",
      url: '//localhost:8000/secure',
      dataType: "jsonp",
      success: function(data) {
        console.log(data)
      }    
   });
});

Output.json

({"posted_date":"25 Jun 2015 ","posted_ID":"3433","content":"this is content","title":"Notice 26/6"},
{"posted_date":"25 Jun 2015 ","posted_ID":"4261","content":"this is content","title":"Welcome"})

So basically when I run the code, it only show the first object

{"posted_date":"25 Jun 2015 ","posted_ID":"3433","content":"this is content","title":"Notice 26/6"}

But the second object is not showing.

What should I do to show BOTH object (or the whole json)?

Note: I must use JSONP else i will get some weird errors...

Henry Lim
  • 13
  • 1
  • 5

2 Answers2

0
x=[{"posted_date":"25 Jun 2015 ","posted_ID":"3433","content":"this is content","title":"Notice 26/6"},{"posted_date":"25 Jun 2015 ","posted_ID":"4261","content":"this is content","title":"Welcome"}]

if you want list of objects then you can pass something like mentioned above Note '[' brace instead of '('.The way you are trying is python tuple way, if you want it in that format then check this answer.Hope it helps

I checked on console and this is what I see enter image description here

Community
  • 1
  • 1
Aameer
  • 1,366
  • 1
  • 11
  • 30
0

try this

$(function(){ 
   $.ajax({
      type: "GET",
      url: '//localhost:8000/secure',
      dataType: "jsonp",
      success: function(data) {
        var response = eval(data);
        $.each(response, function(key, event) {
        console.log(event.d)
        }
      }    
   });
});

Return data like this

{"d":[{"posted_date":"25 Jun 2015 ","posted_ID":"3433","content":"this is content","title":"Notice 26/6"},
{"posted_date":"25 Jun 2015 ","posted_ID":"4261","content":"this is content","title":"Welcome"}]}
Mukesh Kalgude
  • 4,814
  • 2
  • 17
  • 32