Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对于原型ajax,使用上下文的条件是什么?_Javascript_Jquery_Ajax_Prototype - Fatal编程技术网

Javascript 对于原型ajax,使用上下文的条件是什么?

Javascript 对于原型ajax,使用上下文的条件是什么?,javascript,jquery,ajax,prototype,Javascript,Jquery,Ajax,Prototype,使用jquery,您可以在ajax请求中访问此,如下所示: $.ajax({ url: "https://example.com/some_api/", context: this, type: 'GET', success: function(data) { //can access this inside now } 以下调用的原型的等效值是什么 new Ajax.Request(url, { onSuccess:

使用jquery,您可以在ajax请求中访问此,如下所示:

$.ajax({
    url: "https://example.com/some_api/",
    context: this,
    type: 'GET',
    success: function(data) 
    {
       //can access this inside now
    }
以下调用的原型的等效值是什么

new Ajax.Request(url, 
{
    onSuccess: function(data)
    {

    }
});
您可以使用bind():


这将导致回调内部的内容与回调外部的内容相同。除此之外,您还可以绑定到对象,以便在回调中获得自定义的此对象。

太棒了!当我明天开始工作的时候,我会试试这个,这看起来确实是原型中的正确方法。一旦我测试它就会接受。请记住,您可以绑定任何函数,而不仅仅是原型中的回调。这包括jQueryAjax回调。。。
new Ajax.Request(url, 
{
    onSuccess: (function(data)
    {

    }).bind(this)
})