• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need to perform an insert operation with AJAX

 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello please help

I have a textarea on to the jsp page where user can enter a comment , i am using AJAX to submit the data .

I am taking this data inside send method of the XMLHttpRequest.




My question is that , after performing the operation , how can i inform the status of the insert to the user .


Please guide me with your valuable suggestions.



 
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the property readyState is 4 that means the response is complete and we can get our data.

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello West ,

In the DAO implementation class , i am using



This may either insert successfully or may also , so how do i capture the status ??
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to return something back in the Ajax call that says if it was a success or failure. It is up to you how you return it back and get the result as K West pointed out.

Eric
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Eric ,

This was the response i was looking for till now .

As you said " It is up to you how you return it back and get the result"

what do you suggest me to do here ?

Can you please give me an idea how to construct a return type and depend on what conditions .
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Returning a JSON response with data seems to be called for.

That data can be as simple as true or false (success or failure), or a complex construct that contains severities and messages. Depends upon your needs.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am planning to implement in this way :

Declare a string str ;

If an insert fails under the catch block



Am i going in a right way ?
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Returning a JSON response with data seems to be called for.

That data can be as simple as true or false (success or failure), or a complex construct that contains severities and messages. Depends upon your needs.



Can you please point to a link or give an idea of how to achieve this ?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSON is a good place to start

Eric
 
K West
Ranch Hand
Posts: 58
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Is this in your jsp?

If so, you have to just send this back to ajax call by



or


at end of your jsp page.

And then get it in ajax response



And then check weather the resp is sucess or error.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:JSON is a good place to start

Eric



JSON inside DAO implementation class ??
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

PavanPL KalyanK wrote:JSON inside DAO implementation class ??


If your DAOs are in the business of generating a response, then you are definitely doing it wrong.

When a business operation returns its result status, it is the job of the presentation layer to create a response. That response can be a JSON-formatted construct that's easy to consume (much easier than XML) in JavaScript.

If you are doing Ajax "by hand", you're just making things hard on yourself. You should be using a library such as jQuery (or other of your choice) which makes Ajax, and evaluating JSON responses, easy as pie.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear thanks ,
reply
    Bookmark Topic Watch Topic
  • New Topic