Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
jQuery-Ajax suces参数作为对象函数_Jquery - Fatal编程技术网

jQuery-Ajax suces参数作为对象函数

jQuery-Ajax suces参数作为对象函数,jquery,Jquery,jQuery-ajax成功参数 我想知道如何在success参数上为ajax函数提供一个对象方法(函数)(对不起我的英语) 假设我已经设置了ajax.setup,其中包含了在服务器上调用php所需的全部内容 function myClass(id) { this.id = id; this.showValues=function(xml) { alert(this.id); // to prove we r in the right object alert(ty

jQuery-ajax成功参数 我想知道如何在success参数上为ajax函数提供一个对象方法(函数)(对不起我的英语)

假设我已经设置了ajax.setup,其中包含了在服务器上调用php所需的全部内容

function myClass(id)
{
  this.id = id;

  this.showValues=function(xml) 
  {
    alert(this.id); // to prove we r in the right object
    alert(typeof(xml)); // to prove we got the xml     
  };

  this.retrieveValues=function()
  { 
    // wont call the method, this is just text, like writing sucess:"hello"
    $.ajax({success: this.id+'.showValues'}); 


   // calls the method but this.id is undefined (xml is received tho)
    $.ajax({success: this.showValues}); 


    // wont call the method
    $.ajax({success: new Function(this.id+'.showValues')}); 


    // calls the method with the right id but xml is undefined
    $.ajax({success: new Function(this.id+'.showValues()')}); 


    // js error - "xml not defined"
    $.ajax({success: new Function(this.id+'.showValues(xml)')}); 


    // of course, next line works, but i dont wanna define the function here
     $.ajax({success: function() { alert(this.id); alert(typeof(xml)); } });    

  };

}


// even declaring the object as global, so the class has a chance to call a method using the var name
// wich is this.id+'.retrieveValues' ==> object1.retrieveValues
var object1;

function Main() // main =d
{
  object1 = new myClass('object1');
  object1.retrieveValues();

}
再次为我糟糕的英语道歉。。仍在学习=d
我希望有人能帮助我,谢谢你

使用函数api找到它的帮助
$.ajax({success: new Function("xml",this.id+'.showValues(xml)')});