2

我有一个不属于我的网站。有很多 JavaScript 函数可以进行 ajax 调用。我想知道是否有可能修改这些函数,以便在成功的 ajax 请求后调用我的 JavaScript 函数。也许有可能注入另一个ajax查询结果代码处理程序?

更新

也许我应该添加更多内容......这个 ajax 调用是通过使用 xajax 库实现的。我找到了这样一段代码:

<script type="text/javascript" charset="UTF-8">
/* <![CDATA[ */
try { if (undefined == xajax.config) xajax.config = {}; } catch (e) { xajax = {}; xajax.config = {}; };
xajax.config.requestURI = "xajax_loader.php";
xajax.config.statusMessages = false;
xajax.config.waitCursor = true;
xajax.config.version = "xajax 0.5 rc1";
xajax.config.legacy = false;
xajax.config.defaultMode = "asynchronous";
xajax.config.defaultMethod = "POST";
/* ]]> */
</script> 

我不知道 xajax 库,但也许有一种方法可以在配置中添加一些东西,以便成功后的请求调用 JavaScript 函数?

4

2 回答 2

1

可以替换 javascript 函数定义。这是一些简单的代码:

<script>
   function xyz() {alert('xyz');}
</script>
<body>
    <button onclick="xyz();">Run xyz</button>
    <button onclick="alert(xyz);">Show xyz</button>
    <button onclick="xyz=function(){alert('xxxxyz');};">Replace xyz</button>
</body>

我创建了一个小提琴http://jsfiddle.net/k565L/来试试这个。但我不知道是否可以替换跨站点javascript函数。

于 2013-12-25T02:21:12.370 回答
0

The source code is available here: https://github.com/Xajax/Xajax/blob/master/xajax_js/xajax_core_uncompressed.js

You might consider doing something like this:

xajax.origCompleteResponse = xajax.completeResponse;
xajax.completeResponse = function(oRequest) {
    // Here you could do anything you want.
    // For example check the request object:
    console.log(oRequest);
    // And then return a call to the original function:
    return xajax.origCompleteResponse.apply(xajax.origCompleteResponse, arguments);
};

Another way of doing the same thing:

(function() {
    var super = xajax.completeResponse; // You can use any variable name you like.
    xajax.completeResponse = function(oRequest) {
        // Here you could do anything you want.
        // For example check the request object:
        console.log(oRequest);
        // And then return a call to the original function:
        return super.apply(super, arguments);
    };
}());

See definition here: https://github.com/Xajax/Xajax/blob/master/xajax_js/xajax_core_uncompressed.js#L3666

于 2013-12-25T03:00:04.370 回答