Results 1 to 2 of 2

Thread: JQuery problem

  1. #1
    Join Date
    Dec 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JQuery problem

    Here is a JQuery AJAX call from a tutorial

    Code:
    <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

    Code:
    <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 ?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I must have been absent that day

    Anyways, by itself the construct:

    Code:
    $("report")
    would represent all tags named 'report' in the document.

    Code:
    $("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:

    Code:
    <weather>
    	<report>Sunny with a chance of rain later</report>
    </weather>
    In which case:

    Code:
    $("report", xml).text()
    would return:

    Sunny with a chance of rain later
    Last edited by jscheuer1; 06-23-2010 at 04:27 AM. Reason: spelling
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •