jQuery中的jQuery.ajaxSetup()方法是什麼?
jQuery.ajaxSetup() 方法為將來的 AJAX 請求設定全域性變數。以下為該方法所用所有引數的描述 -
假設我們在 result.html 檔案中有以下 HTML 內容,
<h1>THIS IS RESULT...</h1>
下例顯示了該方法的使用。在這裡我們使用成功處理程式來填充返回的 HTML
<html> <head> <title>The jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function() { $("#driver").click(function(event){ // Do global setting. $.ajaxSetup({ url: "result.html" }); $.ajax( { success:function(data) { $('#stage').html(data); } }); }); }); </script> </head> <body> <p>Click on the button to load result.html file:</p> <div id = "stage" style = "background-color:#cc0;"> STAGE </div> <input type = "button" id = "driver" value = "Load Data" /> </body> </html>
廣告