我提供了一個示例場景,以幫助您開始:
<!-- Include this jQuery library in your HTML somewhere: -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script
這可能是最好的一個外部JS文件裏面包括:
//Listen when a button, with a class of "myButton", is clicked
//You can use any jQuery/JavaScript event that you'd like to trigger the call
$('.myButton').click(function() {
//Send the AJAX call to the server
$.ajax({
//The URL to process the request
'url' : 'page.php',
//The type of request, also known as the "method" in HTML forms
//Can be 'GET' or 'POST'
'type' : 'GET',
//Any post-data/get-data parameters
//This is optional
'data' : {
'paramater1' : 'value',
'parameter2' : 'another value'
},
//The response from the server
'success' : function(data) {
//You can use any jQuery/JavaScript here!!!
if (data == "success") {
alert('request sent!');
}
}
});
});
非常感謝你spryno724,我將在下班時嘗試這個。謝謝 – NicTesla 2011-05-10 08:35:07
非常感謝你!驗證了幾種可能性之後,我拿出了你提到的那個。對於所有其他人來說,誰想要更多的解決方案使用代理服務器(就像其他人在這裏用PHP展示的,或者YQL,這是一個雅虎代理服務器,或者如果你使用tomcat,你可以自己編寫代理服務器),或使用腳本標籤,就像我選擇的解決方案。我需要它作爲我的學士論文,所以謝謝你們! BR – NicTesla 2011-05-16 19:28:44
沒問題,很高興能幫到你! – 2011-05-16 21:55:15