Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding implementing JQuey.load()

 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first sample program using JQuery... try to insert test1 -text box value through jsp,...but ends up with javascript error - unexpected call to method.
in jsp, "name" parameter is printing..

TestJQ.jsp

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please indent your code properly; without proper indentation JavaScript becomes rather difficult to read. It'd also be easier if you didn't use a leading "$" in your variable names--it's noisy and somewhat confusing.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you returning XML?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using $ in variable names is not a best practice in JavaScript.
You are mixing getElementById and jQuery, not sure why you did that.

Description of load from jQuery's site: Load data from the server and place the returned HTML into the matched element.

What browser is the error happening in?
When you call the jsp page directly, is it loading in the browser? [Type jsp url into browser]

Eric
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.. I deleted the messy part. Now I just want to get one string from jsp, and should be placed in an empty textbox in html.

In browsers -- firefox - not showing any result,
IE - alerts whole jsp page,
eclipse editor - alerts the error " unexpected call to method or property access"


Please tell me is this the correct way to send a string to html ?
TestJQ.jsp
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So there are all sorts of issues here with your code. First, you seem to be expecting XML returned from the $.load() function. That may very well be however, the $.load() doens't give 2 beans about the data. It just simply dumps it into the selector you've chosen. Secondly, you're overcomplicating the JSP....



And the TestJQ.jsp



Honestly, that's all there is to it.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are expecting XML in return and you need to parse it, you won't be able to use $.load(). You'd be better of with $.get()/$.post()
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then how to load the text box, actually I have a dropdown box in html,
to be loaded from database (in jsp).
Todo this, I just tried with this small example.
ok, here am trying the populate textbox, whose value has to be populated from jsp,,
Jsp code :::

eventhough , it is not populating ...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a 'textbox' in HTML. What HTML element are you trying to populate? Hint: Show us.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I just re-read everything. What you are trying to do doesn't work. $.load() won't populate input elements. What you need to do is something like this...



Assuming you want to populate:

 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, thank you Gregg, working fine..
Is this the same way to work with dropdown box ?, in which array of strings has to be populated !!!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
indu yeturu wrote:thank you, thank you Gregg, working fine..
Is this the same way to work with dropdown box ?, in which array of strings has to be populated !!!


That's one way, yes. But you would be better off returning the options for the select as JSON. It's much easier to work with in JavaScript.
 
indu yeturu
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you ... I will try with JSON...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic