Tuesday, 15 September 2015

java - How to pass parameter from prototypejs client to rest web service -



java - How to pass parameter from prototypejs client to rest web service -

i have rest web service

@path("/postitem") @produces({ mediatype.application_xml, mediatype.application_json }) public item postitem(@queryparam("name") string name, @queryparam("price") string price) { system.out.println(name); system.out.println(price); homecoming new item(name , price); }

and utilize prototypejs javascript lib invoke above rest web service client side below code snippet.

<script> new ajax.request('/some_url', { method:'post', parameters: {name: 'apple', price: 12} onsuccess: function(transport) { var response = transport.responsetext || "no response text"; alert("success! \n\n" + response); }, onfailure: function() { alert('something went wrong...'); } }); </script>

problem : not able correctly pass parameter name , cost of service method.

i passing 2 parameters in client in service side parameter 'name' getting mapped(that wrong value). when print name , cost next

system.out.println(name); ==> name='apple'&price=12 system.out.println(price); == null

how can pass parameter service prototypejs client 'name' gets value apple , 'price' gets value 12.

put quotes around "name" ie

before

parameters: {name: 'apple', price: 12}

after

parameters: {'name': 'apple', 'price': 12}

'name' keyword not getting passed correctly in object

edit

more things try...

make sure using latest prototypejs version 1.7.1

add comma after parameters: {name:'apple',price:12},

double check browser passing parameters correctly using chrome dev tools or firebug - if beingness passed correctly check end script

java javascript rest prototypejs

No comments:

Post a Comment