Если класс содержит какие-либо шаблонные функции членства, можно специализировать ту функцию членства для удовлетворения потребностям. Даже если исходный разработчик не думал о нем.
safe.h
class safe
{
int money;
public:
safe()
: money(1000000)
{
}
template <typename T>
void backdoor()
{
// Do some stuff.
}
};
main.cpp:
#include <safe.h>
#include <iostream>
class key;
template <>
void safe::backdoor<key>()
{
// My specialization.
money -= 100000;
std::cout << money << "\n";
}
int main()
{
safe s;
s.backdoor<key>();
s.backdoor<key>();
}
Вывод:
900000
800000
Итак, основываясь на предложении использовать объект XmlHttpRequest, возвращаемый функцией $ .get, я придумал следующее:
function doStuff(){
var ajaxRequest = $.ajax({
url : 'url/url/url',
type : "GET",
success : function(data){
ajaxRequest = null;
doSuccessStuff(data);
}
});
$('#dialog').dialog({
title: 'Stuff Dialog',
bgiframe: true,
modal: true,
buttons: {
Cancel: function() {
if (ajaxRequest)
ajaxRequest.abort();
doCancelStuff();
}
}
});
}
Кажется, он работает и кажется мне чище.
No method in jQuery, but you can just use XmlHttpRequest object returned from the jQuery get/post/ajax functions.
From the jQuery blog:
// Perform a simple Ajax request
var req = $.ajax({
type: "GET",
url: "/user/list/",
success: function(data) {
// Do something with the data...
// Then remove the request.
req = null;
}
});
// Wait for 5 seconds
setTimeout(function(){
// If the request is still running, abort it.
if ( req ) req.abort();
}, 5000);
It appears so, though I've never done it.
$.get
returns an XmlHttpRequest
object, which has an abort()
method you can call. Maybe try that?