johnnys Posted November 21, 2014 Share Posted November 21, 2014 I am retrieving Google Books info in JSON format and displaying it inside a div. I would like to send the contents of this div (name, title, description) to my database using Ajax. Currently only the ISBN field sends because I have it declared as a variable. However my question is, how do I send the other fields (name, title, author). How do I declare these also, I'm not sure what format they need to be in etc. My JS $(document).ready(function() { $('#submit').click(function(ev) { ev.preventDefault(); var isbn = $('#isbn_search').val(); //get isbn direct from input var url='https://www.googleapis.com/books/v1/volumes?q='+isbn; $.getJSON(url,function(data){ $.each(data.items, function(entryIndex, entry){ var html = '<div class="results well">'; html += '<h3>' + entry.volumeInfo.title + '</h3>'; html += '<div class="author">' + entry.volumeInfo.authors + '</div>'; html += '<div class="description">' + entry.volumeInfo.description + '</div>'; }); }); }); }); My Ajax; $.ajax({ type: 'POST', url: 'addIsbnScript.php', data: { 'isbn' : isbn, 'title' : title 'subtitle' : subtitle, 'authors' : authors, 'description' : description }, success: function () { $.growl({ message: " Record added" }); } }); Note, if i manually set the vars like below they all do successfully send to my database, so I know my query is working ok var title = "some text", var author = "some text", Var description = "some text" Thanks in advance for any help, newbie here (incase it wasn't obvious!). J Link to comment https://forums.phpfreaks.com/topic/292615-ajax-to-send-json-data-to-db/ Share on other sites More sharing options...
johnnys Posted November 21, 2014 Author Share Posted November 21, 2014 Actually figured it out, pretty simple. I just had to change my code as follows; 'title' : entry.volumeInfo.title Link to comment https://forums.phpfreaks.com/topic/292615-ajax-to-send-json-data-to-db/#findComment-1497182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.