Pulling Data to Pass to Ajax Function step 47
Now, we need to add the new book to the database using Ajax. We need to do this using javascript.
First, you need to add an id to the html:text forms so you can properly call the data. In struts, you will use the styleId. Next to the the property="book", you want to add a styleId="book", and next to the property="author", you want to add the styleId="author", and next to the property="bookPublisher", you want to add styleId="bookPublisher", and next to property="categoryId", you want to add styleId="category". Do not add this attribute to the html:optionsCollection because that would be invalid. You will add these in your addbook.jsp page. Some browsers don't require an id, but some do. If you don't put an id, then it won't work in firefox. Also, firefox is case sensitive so when you call the attribute, make sure you use the same case. In your retrieveURL function in your classiclayout.jsp page, you need to grab the elements that the user has inputted.
You will add thes to the beginning of the retrieveURL function.
book=document.getElementById("book").value
author=document.getElementById("author").value
publisher=document.getElementById("bookPublisher").value
category=document.getElementById("category").value
(Make sure they are the same case as the styleId)
These variables will grab the data you need to pass it to the Ajax call so you can add the new object to the database.
Go To Step 48

0 comments:
Post a Comment