parsing json (from pylons) using jquery

I have set up a pylons server to accept requests of the form "/searcher?q=blahblah". This returns some nice json of the form:

[{"name":"onefish","type":"one"},{"name":"twofish",type:"two"}]

I get this using the javascript:

function search() {
   var query = $('#search_box').val();
   $.getJSON('/searcher',
      {
         q: query
      },
      function(data) {
         $.each(data,function(index,element) {
            $(body).append($('<div>',{text: element.name}));
         }
      }
   );
}

This successfully queries the server when called and it is called (the server gives response code 200). However, the code does not add anything to the body. The same nothing happens when I replace $(body).append(...); with something like $('#some_id').html(...);. Is there something wrong with my query, my parsing, or my output?

Answers


I solved this myself. body needs to be in quotes...


Need Your Help

Valid filenames (for download) in IE?

asp.net asp.net-mvc internet-explorer http unicode

I have an action in aspnet mvc that returns a FileContentResult. I have noticed that when the fileDownloadName contains umlauts (ie åäöü) Internet Explorer can't read the file name at all.

send data from standby application to active application

c#-4.0

while my application in standby mode (not the active one),I want it to write in the text box of the active application (while the cursor is in that text box )

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.