wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes how to access parameter which was sent from jquery getJSON method inside the AJAX resource? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to access parameter which was sent from jquery getJSON method inside the AJAX resource?" Watch "how to access parameter which was sent from jquery getJSON method inside the AJAX resource?" New topic
Author

how to access parameter which was sent from jquery getJSON method inside the AJAX resource?

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 586
I am sending a parameter from Jquery AJAX method getJSON using below syntax:



This is working fine as I checked in debugger.Control is going inside the ajax resourece(AJAX action in this case).

But now I do not know how to access this parameter v which is sent from jquery inside the ajax resource (AJAX action) or by what name should I access it and how.Please advice.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Just sending v isn't valid. Check the documentation.

The data parameter should be a set of name value pairs which in turn serve as the request parameters. The easiest way to do this is to simply use an object hash.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 586
Thanks.I am checking the documentation of method for necessary changes. Once I figure out how to do this, how to fetch this in the AJAX resource(Ajax action in this case). How and by what name should this data parameter be fetched in ajax resource.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

By the name that you give it in the object hash.
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 586
does it mean inside the AJAX Action I can use assuming myName is the name given to the object hash?
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 586
I checked the documentation for getJSON method.It is as below:


jQuery.getJSON( url [, data ] [, success( data, textStatus, jqXHR ) ] )

data
Type: PlainObject
A plain object or string that is sent to the server with the request.

but it says "A plain object or string that is sent to the server with the request".Doesnt that mean parameter can be sent as string?

thanks.
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 586
I got some success in sending the parameter from getJSON method to ajax resource.

I sent the parameter from getJSON method as



remaining code



In the above code I am able to send the selected radiobutton parameter to AJAX action as name parameter.


Now when I access the name in the AJAX resource it comes correct in debugger. I selected action 2 and on checking in debugger it is reflected in AJAXAction resource as below:



If I check the value in temp in debugger it comes as 2 which is correct(2nd option was selected).

However I had to send { name: v, value: null } as parameter which required key value pair.

I just had to send v but since syntax is asking for key value pair I sent as null. Please advice how should I send this parameter. It is working fine but is sending { name: v, value: null } the correct way?

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

Of course not. I really have no idea what you are trying to do with the null.

Request parameters are name/value pairs. In a normal form submission, the name of the element and its value are used. When you want to send values yourself via Ajax, you supply an object hash with the name value pairs:
It's as simple as that.

On the server, request parameters are obtained n the same way regardless of how they are defined at the client.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to access parameter which was sent from jquery getJSON method inside the AJAX resource?
 
Similar Threads
how to populate HTML div using AJAX to iterate and display arrayList values.
unable to send selected radiobutton as parameter to ajax method getJSON.
Post Does not Return new Values
Pass object to frontend using servlet and ajax
not able to pass request parameters when the JSON call is made from Open portal