jQuery:简单Ajax请求+事件处理程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery:简单Ajax请求+事件处理程序相关的知识,希望对你有一定的参考价值。
Here is a basic example as to how to set up an Ajax request.
<!-- jQuery Framework --> <script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" charset="utf-8"> function getData( url ){ $.ajax({ url: url, dataType: "json", encoding:"UTF-8", beforeSend: ajaxStart, success: ajaxSuccess, error: ajaxError, complete: ajaxComplete }); } function ajaxStart( xhrInstance ){ //A. Clear Any Previously Written html //B. Show Preloader console.log( "ajaxStart:" ) } function ajaxError( xhrInstance, message, optional ){ console.log( "ajaxError:" ); } function ajaxComplete( xhrInstance, status ){ //A. Remove any preloaders console.log( "ajaxComplete:" ); } function ajaxSuccess( data, status ){ //Write your Parse XML Function parseData( data ); } function parseData( data ){ console.log( "parseData:", data ); } </script> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ getData("http://path/to/xml/or/json/feed"); } </script>
以上是关于jQuery:简单Ajax请求+事件处理程序的主要内容,如果未能解决你的问题,请参考以下文章