2013-05-13 185 views
1

我有這個程序運行在與pythoncom.PumpMessages()循環。 這個程序運行時,它需要輸入並通過它存儲。 當輸入達到一定長度時,我希望異步發送一個HTTP POST請求到我在雲中的數據庫,這樣程序就不會在請求發送時停止輸入。我不需要服務器的請求,但它會很好。如何使異步HTTP POST請求

這可能嗎?我很難搞清楚這一點。現在它同步進行。

謝謝!

回答

0

JavaScript適用於任何瀏覽器,無需添加庫。

這非常適合加載頁面的某些部分而不會拖延UI,但如果發送很多請求(例如> 100),則使用其他方法(例如,服務器或NodeJS)。

<p id="demo">Customer info will be listed here...</p> 

<script> 
function showCustomer(str) { 
    var xmlhttp; 
    if (str == "") { 
    document.getElementById("demo").innerHTML = ""; 
    return; 
    } 
    xmlhttp = new XMLHttpRequest(); 
    xmlhttp.onreadystatechange = function() { 
    if (this.readyState == 4 && this.status == 200) { 
     document.getElementById("demo").innerHTML = this.responseText; 
    } 
    }; 
    xmlhttp.open("GET", "yourFile.php?queryVariable="+str, true); 
    xmlhttp.send(); 
} 
</script> 

來源:http://www.w3schools.com/xml/tryit.asp?filename=try_dom_xmlhttprequest_database

GET:http://www.w3schools.com/xml/tryit.asp?filename=try_dom_xmlhttprequest_first

這裏更多:http://www.w3schools.com/xml/dom_http.asp