JQuery – параметр успеха Ajax как объектная функцияJquery

Программирование на jquery
Ответить
Anonymous
 JQuery – параметр успеха Ajax как объектная функция

Сообщение Anonymous »

jQuery — параметр успеха ajax
Я хочу знать, как передать метод (функцию) объекта в параметре успеха функции 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 though)
$.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 don't want to 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
// which is this.id+'.retrieveValues' ==> object1.retrieveValues
var object1;

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

}
еще раз извините за мой плохой английский... все еще учусь.
Надеюсь, кто-нибудь сможет мне помочь, спасибо

Подробнее здесь: https://stackoverflow.com/questions/174 ... t-function
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»