2011-06-12 38 views
1

我不知道如何寫這個腳本。我需要使用某個URL加載結果(例如:localhost/index.php?action = get & type = 29),並且此結果爲進一步處理提供變量。我需要在Jquery上創建它。謝謝。實時加載結果(ajax)

回答

2

有jQuery的功能可以使用,你必須使用簡單.load()函數,將解析HTML到一個元素或者一個快速的負荷。用法:

$('#element').load('http://www.urlgoeshere.com/'); 

隨着處理事件與AJAX與再次寫入選項,你有很多選項可以選擇:

這些選項下面是使用.ajax()功能,但品牌寫作更簡單:

編輯:你的 「刷新」,則可以使用setTimeout功能重複Ajax調用:

setTimeout(function() 
{ 
    $.ajax({ 
     type: "POST", 
     url: "some.php", 
     data: "action=get&type=29", 
     success: function(arg){ 
      // do something 
     } 
    }); 
}, 1000); // This will "refresh" every 1 second 
0

可以使用

$.ajax({ 
    url: "localhost/index.php", 
    data: "action=get&type=29", 
    success: function(data, status, xhr){ 
     // data is the response from the server, status is the http status code, 
     // xhr is the actual xhr 
    }, 
    error: function(){ 
    }, 
    ... 
}); 

得到的結果。

請務必定義successerror回調以在返回數據時處理數據。

看這裏http://api.jquery.com/jQuery.ajax/上手。

+0

如何單元刷新的時間? – Koiw 2011-06-12 17:11:15

+0

使用setTimeout(...) – hvgotcodes 2011-06-12 17:16:39

+0

謝謝。它解決了我的問題。 – Koiw 2011-06-12 17:19:40

0
$.ajax({ 
    type: "POST", 
    url: "some.php", 
    data: "action=get&type=29", 
    success: function(arg){ 
     // do something 
    } 
}); 
+0

如何自動刷新時間單位? – Koiw 2011-06-12 17:15:26