【发布时间】:2011-04-13 04:43:22
【问题描述】:
有人可以告诉我这是否可以通过 Ajax 实现。我想将一个外部站点加载到一个页面上,然后使用 jQuery、jScript、php 或某种方法来模拟对我刚刚加载的外部站点页面的点击。
本站将不允许传统的post/get
<script type="text/javascript" language="javascript">
//<![CDATA[
function FriendCenterObject() {
var fcAction = function(actionUrl, gamerTag, responseHandler) {
responseHandler = responseHandler || function(response) {
if (response.status != 0) {
DisplayMessageDialog('Error', response.view, 'Close', null, MessageLevelType.Error);
}
else {
DisplayMessageDialog('Message', response.view, 'Close', FriendCenter.RefreshContentAction);
}
}
$.post(actionUrl, { 'gamerTag': gamerTag }, responseHandler);
};
this.AddFriend = function(gamerTag) {
gamerTag = $.trim(gamerTag); // trim leading and trailing whitespaces
if (gamerTag != "") {
fcAction('/en-US/FriendCenter/SendFriendRequest', gamerTag);
}
return false;
};
this.RefreshContentAction = function(){};
};
var FriendCenter = new FriendCenterObject();
//]]>
</script>
这是我希望用户能够点击的链接
<a href="#" onclick="FriendCenter.AddFriend('mirco')">Add to Friends List</a>
我做了更多调查,它肯定使用了内容类型为 Content-Type:application/json 的 Post 方法
【问题讨论】:
-
这需要更详细的回答。您正在将外部站点“加载”到包含您的脚本的页面上——这是通过
iframe还是某种 AJAX 请求? -
它在您的域内吗?因为如果不是,你不应该能够。如果您需要自动点击外部网站,您可以查看seleniumhq.org
-
这可能对你有用。当我需要做类似的事情时,我会使用它。 stackoverflow.com/questions/2149867/…
-
请看上面我已经添加了来自外部页面的编码部分,我试图让用户点击。