词条 | Ajax (programming) |
释义 |
| name = AJAX | title = Asynchronous JavaScript and XML | released = March 1999 | influenced by = JavaScript and XML | File extensions = .js | File format = JavaScript }} Ajax (also AJAX {{IPAc-en|ˈ|eɪ|dʒ|æ|k|s}}; short for asynchronous JavaScript and XML)[1][1] is a set of web development techniques using many web technologies on the client side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. By decoupling the data interchange layer from the presentation layer, Ajax allows web pages and, by extension, web applications, to change content dynamically without the need to reload the entire page.[2] In practice, modern implementations commonly utilize JSON instead of XML. Ajax is not a single technology, but rather a group of technologies. HTML and CSS can be used in combination to mark up and style information. The webpage can then be modified by JavaScript to dynamically display—and allow the user to interact with—the new information. The built-in XMLHttpRequest object within JavaScript is commonly used to execute Ajax on webpages allowing websites to load content onto the screen without refreshing the page. Ajax is not a new technology, or different language, just existing technologies used in new ways. HistoryIn the early-to-mid 1990s, most Web sites were based on complete HTML pages. Each user action required that a complete new page be loaded from the server. This process was inefficient, as reflected by the user experience: all page content disappeared, then the new page appeared. Each time the browser reloaded a page because of a partial change, all of the content had to be re-sent, even though only some of the information had changed. This placed additional load on the server and made bandwidth a limiting factor on performance. In 1996, the iframe tag was introduced by Internet Explorer; like the object element, it can load or fetch content asynchronously. In 1998, the Microsoft Outlook Web Access team developed the concept behind the XMLHttpRequest scripting object.[3] It appeared as XMLHTTP in the second version of the MSXML library,[3][4] which shipped with Internet Explorer 5.0 in March 1999.[5] The functionality of the XMLHTTP ActiveX control in IE 5 was later implemented by Mozilla, Safari, Opera and other browsers as the XMLHttpRequest JavaScript object.[6] Microsoft adopted the native XMLHttpRequest model as of Internet Explorer 7. The ActiveX version is still supported in Internet Explorer, but not in Microsoft Edge. The utility of these background HTTP requests and asynchronous Web technologies remained fairly obscure until it started appearing in large scale online applications such as Outlook Web Access (2000)[7] and Oddpost (2002). Google made a wide deployment of standards-compliant, cross browser Ajax with Gmail (2004) and Google Maps (2005).[8] In October 2004 Kayak.com's public beta release was among the first large-scale e-commerce uses of what their developers at that time called "the xml http thing".[9] This increased interest in AJAX among web program developers. The term Ajax was publicly used on 18 February 2005 by Jesse James Garrett in an article titled Ajax: A New Approach to Web Applications, based on techniques used on Google pages.[10] On 5 April 2006, the World Wide Web Consortium (W3C) released the first draft specification for the XMLHttpRequest object in an attempt to create an official Web standard.[11] The latest draft of the XMLHttpRequest object was published on 06 October 2016.[12] TechnologiesThe term Ajax has come to represent a broad group of Web technologies that can be used to implement a Web application that communicates with a server in the background, without interfering with the current state of the page. In the article that coined the term Ajax,[10][2] Jesse James Garrett explained that the following technologies are incorporated:
Since then, however, there have been a number of developments in the technologies used in an Ajax application, and in the definition of the term Ajax itself. XML is no longer required for data interchange and, therefore, XSLT is no longer required for the manipulation of data. JavaScript Object Notation (JSON) is often used as an alternative format for data interchange,[13] although other formats such as preformatted HTML or plain text can also be used.[14] A variety of popular JavaScript libraries, including JQuery, include abstractions to assist in executing Ajax requests. Asynchronous HTML and HTTP (AHAH) involves using XMLHTTPRequest to retrieve (X)HTML fragments, which are then inserted directly into the Web page. Drawbacks
ExamplesJavaScript exampleAn example of a simple Ajax request using the GET method, written in JavaScript. get-ajax-data.js: send-ajax-data.php: Many developers dislike the syntax used in the XMLHttpRequest object, so some of the following workarounds have been created.jQuery exampleThe popular JavaScript library jQuery has implemented abstractions which enable developers to use Ajax more conveniently. Although it still uses XMLHttpRequest behind the scenes, the following is the same example as above using the 'ajax' method. jQuery also implements a 'get' method which allows the same code to be written more concisely.$.get('send-ajax-data.php').done(function(data) { console.log(data); }).fail(function(data) { console.log('Error: ' + data); }); Fetch exampleFetch is a new native JavaScript API. Although not yet supported by all browsers, it is gaining momentum as a more popular way to execute Ajax.{{Citation needed|date=March 2018}} According to [https://developers.google.com/web/ilt/pwa/working-with-the-fetch-api Google Developers Documentation], "Fetch makes it easier to make web requests and handle responses than with the older XMLHttpRequest." fetch('send-ajax-data.php') .then(data => console.log(data)) .catch(error => console.log('Error:', error)); // ES7 async/await example: async function doAjax() { try { const res = await fetch('send-ajax-data.php'); const data = await res.text(); console.log(data); } catch (error) { console.log(error); } } doAjax(); As seen above, fetch relies on JavaScript [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise promises]. See also
References1. ^{{Cite web|url=https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX|title=Ajax - Web developer guides|website=MDN Web Docs|access-date=2018-02-27}} 2. ^1 {{cite book | url=http://www.wrox.com/WileyCDA/Section/id-303217.html | title=Beginning Ajax | accessdate=24 June 2008 | publisher=wrox | date=March 2007 | first=Chris | last=Ullman | isbn=978-0-470-10675-4 | archiveurl=https://web.archive.org/web/20080705101852/http://www.wrox.com/WileyCDA/Section/id-303217.html | archivedate=5 July 2008 | deadurl= no}} 3. ^1 {{cite web |url=http://www.alexhopmann.com/xmlhttp.htm |title=Article on the history of XMLHTTP by an original developer |publisher=Alexhopmann.com |date=2007-01-31 |accessdate=2009-07-14 |deadurl=yes |archiveurl=https://web.archive.org/web/20070623125327/http://www.alexhopmann.com/xmlhttp.htm |archivedate=23 June 2007 |df=dmy-all }} 4. ^{{cite web|url=http://msdn.microsoft.com/en-us/library/ms759148(VS.85).aspx |title=Specification of the IXMLHTTPRequest interface from the Microsoft Developer Network |publisher=Msdn.microsoft.com |accessdate=2009-07-14}} 5. ^{{cite web |url=http://blogs.msdn.com/ie/archive/2006/01/23/516393.aspx |title=Native XMLHTTPRequest object |accessdate=2006-11-30 |last=Dutta |first=Sunava |date=2006-01-23 |work=IEBlog |publisher=Microsoft}} 6. ^{{cite web | url=https://developer.apple.com/internet/webcontent/xmlhttpreq.html | title=Dynamic HTML and XML: The XMLHttpRequest Object | publisher=Apple Inc. | accessdate=25 June 2008 }} 7. ^{{Cite web|last=Hopmann|first=Alex|title=Story of XMLHTTP|url=http://www.alexhopmann.com/story-of-xmlhttp/|work=Alex Hopmann’s Blog|accessdate=17 May 2010|deadurl=yes|archiveurl=https://web.archive.org/web/20100330150027/http://www.alexhopmann.com/story-of-xmlhttp/|archivedate=30 March 2010|df=dmy-all}} 8. ^{{cite web | url=http://www.aaronsw.com/weblog/ajaxhistory | title=A Brief History of Ajax | publisher=Aaron Swartz | date=22 December 2005 | accessdate=4 August 2009 }} 9. ^{{Cite web | last=English|first=Paul|title=Kayak User Interface|url=http://kayaklabs.blogspot.com/2006/04/kayak-user-interface.html|work=OFFICIAL KAYAK.COM TECHNOBLOG|accessdate=22 May 2014}} 10. ^1 2 {{cite web | url=http://adaptivepath.org/ideas/ajax-new-approach-web-applications/ | title=Ajax: A New Approach to Web Applications | publisher=AdaptivePath.com | author=Jesse James Garrett | date=18 February 2005 | accessdate=19 June 2008}} 11. ^1 {{cite web | url=http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/ | title=The XMLHttpRequest Object | publisher=World Wide Web Consortium | date=5 April 2006 | accessdate=25 June 2008 | archiveurl=https://web.archive.org/web/20080516060525/http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/ | archivedate=16 May 2008 | deadurl= no | last1=van Kesteren | first1=Anne | last2=Jackson | first2=Dean | website=W3.org}} 12. ^{{cite web | last1=Kesteren | first1=Anne | last2=Aubourg | first2=Julian | last3=Song | first3=Jungkee | last4=Steen | first4=Hallvord R. M. | title=XMLHttpRequest Level 1 | url=https://www.w3.org/TR/2016/NOTE-XMLHttpRequest-20161006/ | website=W3.org | publisher=W3C | accessdate=2019-02-19}} 13. ^{{cite web | url=http://tapestry.apache.org/tapestry4.1/ajax/json.html | title=JavaScript Object Notation | publisher=Apache.org | accessdate=4 July 2008 | archiveurl=https://web.archive.org/web/20080616113121/http://tapestry.apache.org/tapestry4.1/ajax/json.html | archivedate=16 June 2008 | deadurl=no | df=dmy}} 14. ^{{cite web | url=http://www.devx.com/Webdev/Article/32651 | title=Speed Up Your Ajax-based Apps with JSON | publisher=DevX.com | accessdate=4 July 2008 | archiveurl=https://web.archive.org/web/20080704134131/http://www.devx.com/Webdev/Article/32651 | archivedate=4 July 2008 | deadurl=yes | df=dmy }} 15. ^{{cite web | url=http://www.alistapart.com/articles/userproofingajax | title=User-proofing Ajax | first=Peter | last=Quinsey}} 16. ^{{cite web | url=http://www.w3.org/WAI/intro/aria.php | title=WAI-ARIA Overview | publisher=W3C | accessdate=21 October 2010 | archiveurl=https://web.archive.org/web/20101026062837/http://www.w3.org/WAI/intro/aria.php | archivedate=26 October 2010 | deadurl= no}} 17. ^{{cite web | url=http://articles.sitepoint.com/article/ajax-screenreaders-work | title=Ajax and Screenreaders: When Can it Work? | publisher=sitepoint.com | first=James | last=Edwards | date=5 May 2006 | accessdate=27 June 2008}} 18. ^{{cite web | url=http://dev.w3.org/2006/waf/access-control/ | title=Access Control for Cross-Site Requests | publisher=World Wide Web Consortium | accessdate=27 June 2008 | archiveurl=https://web.archive.org/web/20080514034546/http://dev.w3.org/2006/waf/access-control/ | archivedate=14 May 2008 | deadurl= no}} 19. ^{{cite web | url=http://msdn.microsoft.com/en-us/library/bb735305.aspx | title=Secure Cross-Domain Communication in the Browser | publisher=The Architecture Journal (MSDN) | accessdate=27 April 2010 | archiveurl=https://web.archive.org/web/20100329064533/http://msdn.microsoft.com/en-us/library/bb735305.aspx | archivedate=29 March 2010 | deadurl= no}} 20. ^{{cite web | url=http://gfxmonk.net/2010/07/04/defer-taming-asynchronous-javascript-with-coffeescript.html#1 | title=What is asynchronous programming, and why is it so damn awkward? | publisher=GFX Monk | first=Tim | last=Cuthbertson | accessdate=19 October 2010}} 21. ^{{cite web | url=http://seleniumhq.org/docs/03_webdriver.html#fetching-a-page | title=Selenium documentation: Fetching a Page | publisher=Selenium | accessdate=6 October 2011 }} It is worth noting that if your page uses a lot of Ajax on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded, then you can use Explicit and Implicit Waits. 22. ^{{cite journal|last1=Pimentel|first1=Victoria|last2=Nickerson|first2=Bradford G.|date=2012-05-08|title=Communicating and Displaying Real-Time Data with WebSocket|journal=Internet Computing, IEEE|volume=16|issue=4|pages=45–53|doi=10.1109/MIC.2012.64}} 23. ^1 {{cite web|url=http://www.interaktonline.com/support/articles/Details/Ajax:+Asynchronously+Moving+Forward-Why+use+Ajax%3F.html?id_art=36&id_asc=309 |title=Why use Ajax? |publisher=InterAKT |date=10 November 2005 |accessdate=26 June 2008 |archiveurl=https://web.archive.org/web/20080529080808/http://www.interaktonline.com/support/articles/Details/AJAX%3A%2BAsynchronously%2BMoving%2BForward-Why%2Buse%2BAJAX?.html%3Fid_art=36&id_asc=309 |archivedate=29 May 2008 |deadurl=no }} 24. ^1 {{cite web | url=http://blog.onthewings.net/2009/04/08/deep-linking-for-ajax/ | title=Deep Linking for AJAX}} 25. ^1 {{Cite web | url=http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html|title=HTML5 specification | accessdate=21 October 2011}} 26. ^{{cite web | url=http://googlewebmastercentral.blogspot.ca/2014/05/understanding-web-pages-better.html?m=1 | title=Official news on crawling and indexing sites for the Google index | publisher=Google | first=Erik | last=Hendriks | date=23 May 2014 | accessdate=24 May 2015}} 27. ^{{cite web | url=http://www.ibm.com/developerworks/library/x-sitemaps/index.html | title=Help Web crawlers efficiently crawl your portal sites and Web sites | publisher=IBM | first=Andreas | last=Prokoph | date=8 May 2007 | accessdate=22 April 2009}} 28. ^{{cite web|url=http://googlewebmastercentral.blogspot.co.uk/2015/10/deprecating-our-ajax-crawling-scheme.html|title=Deprecating our AJAX crawling scheme|date=October 14, 2015|publisher=Google Webmaster Central Blog}} External links{{Commons category|AJAX (programming)}}{{wikibooks|AJAX}}
7 : Ajax (programming)|Cloud standards|Inter-process communication|Web 2.0 neologisms|Web development|Articles with example JavaScript code|Articles with example PHP code |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。