Getting Started With jQuery - Ajax The Basics |
Written by Ian Elliot | |||||||
Monday, 24 August 2015 | |||||||
Page 3 of 3
There is another strange extra behavior. You can specify a portion of the returned html data to be used, i.e. a page fragment. If you follow the URL with a space and then a jQuery selector the selector is applied to the data before it is assigned to the matched elements. That is if you write
then the returned HTML is processed using $("#todaysData") and the result including the matched element. For example if myData.txt contains;
then if you try:
You will see that the entire file has been returned in data, but only the first div has been inserted between <body> and </body>. Where Next?This has been a first look at jQuery's Ajax methods. To keep things simple we looked only at the get and very closely related methods. This has the advantage that we can ignore the problem of what happens on the server side because we can simply assume that the data being retrieved is in a file which the sever can load and deliver. However, we have to move on to consider the jQuery client interacting with a program - a PHP page say. In this case we need to consider additional complications such as headers, MIME types, character encodings and so on. In the next chapter we concentrate on the post method and how to send data from the client to the server using Ajax. Summary
More InformationJust jQuery
|
JavaScript Canvas - Fetch API Working with lower-level data is very much part of graphics. This extract from Ian Elliot's book on JavaScript Graphics looks at how to use typed arrays to access graphic data. |
JavaScript Jems - The Inheritance Tax JavaScript should not be judged as if it was a poor version of the other popular languages - it isn't a Java or a C++ clone. It does things its own way. In particular, it doesn't do inheritance [ ... ] |
Other Articles |