PDA

View Full Version : JQuery problem



The_Alligator
06-22-2010, 02:02 PM
Here is a JQuery AJAX call from a tutorial



<script type="text/javascript">
$(document).ready(function() {
$("#getWeatherReport").click(function(){
$cityName = document.getElementById("cityName").value;
$.post("WeatherServlet", {cityName:$cityName}, function(xml) {
$("#weatherReport").html( $("report", xml).text() );
});
});
});
</script>





JSP page



<form method="post">
Enter City :
<input id="cityName" name="cityName" size="30" type="text" />
<input id="getWeatherReport" name="getWeatherReport" type="button" value="Get Weather" />
</form>

<div id="weatherReport" class="outputTextArea"></div>

what is report in the above code ?
Is it a JQuery keyword ?
Can I rename it to anything I like ?
Does it have any dependency elsewhere ?

jscheuer1
06-23-2010, 04:20 AM
I must have been absent that day :)

Anyways, by itself the construct:


$("report")

would represent all tags named 'report' in the document.


$("report").text() would be the text contained in those tags.

It seems pretty clear to me that the intention here is to get the tags (there is probably only one expected) 'report' from the returned xml of the post request and place its text in the element on the page with the id of 'weatherReport'.

It might be helpful to also know that the expected response here is an xml document where tags are not limited to standard HTML tag names. They may have any name.

The returned xml document could look like so:


<weather>
<report>Sunny with a chance of rain later</report>
</weather>

In which case:


$("report", xml).text()

would return:


Sunny with a chance of rain later