javascript - Viewing the JSON from an AJAX call -
i have ajax call -
$('#search').keyup(function() { $.ajax({ type: "get", url: "/main/search/", data: { 'search_text': $('#search').val() }, success: function(data) { alert(data); }, datatype: 'html' }); }); the url redirects django view template doing -
{% if item_list.count > 0 %} {% obj in item_list %} <p>{{obj.name}}</p> {% endfor %} {% else %} no items! {% endif %} this gives following alert -
<p> item1 </p> <p> item2 </p> and on, according search matches.
now learning purposes want see how json response like, , it. however, this-
$('#search').keyup(function() { $.ajax({ type: "get", url: "/main/search/", data: { 'search_text': $('#search').val() }, success: function(data) { alert(data); }, datatype: 'json' }); }); doesn't open alert box.
and, if @ "network" tab in chrome inspector, see response html response previous one.
why happening? how see json response?
you can use console.log(data);
like this:
$('#search').keyup(function() { $.ajax({ type: "get", url: "/main/search/", data: { 'search_text': $('#search').val() }, success: function(data) { console.log(data); }, datatype: 'json' }); });
Comments
Post a Comment