2013-05-13 186 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