我提供了一个示例场景,以帮助您开始:
<!-- 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