HTML and CSS Reference
In-Depth Information
You can mimic a 404 error by changing one of the search words to return an invalid path.
The jQuery AJAX toolkit supports not only getting data, but also posting data to the
server. The default request type is GET. To change a call to a post, you change the value of the
property to POST:
$.ajax({
url: searchPath,
cache: false,
dataType: "xml",
type: "POST",
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
$('#searchResults').append(errorThrown);
}
});
Perhaps the site user knows of additional fruit that fit into a certain category. The page
can be enhanced to allow users to enter the name of a fruit and submit it to the XML file so
that subsequent searches include it. Ideally in this case, you would use the POST method to a
server-side function that would accept this data and store it in the XML file.
Wiring up an event with jQuery
In Objective 2.2, “Raise and handle an event,” you saw how to set up event listeners for
various actions that the DOM or a user's interaction with the DOM could invoke. One of the
most common issues encountered by web developers is cross-browser compatibility. Al-
though this topic is large and this topic doesn't have the space to go into great detail about
cross-browser compatibility, jQuery is one of the toolkits available to help bridge the issue. In
Listing 2-2, you saw an example of jQuery syntax to wire up an event:
$('#searchButton').click(function () {
}
In this sample, the jQuery selector syntax is used to find the search button on the page by
its name. Then the click event is assigned a function that runs when the button is clicked.
This syntax is quite powerful. Aside from being cross-browser friendly, it includes much
flexibility in how event handlers are assigned to objects. This jQuery selector syntax supports
all the same type of searches that the document object exposes. But the part that differenti-
ates jQuery from the document object is that jQuery can assign styles or events to everything
in the result set in one line.
 
 
Search WWH ::




Custom Search