Jump to content

Ajax to send JSON data to DB


Go to solution Solved by johnnys,

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.