Reputation: 575
I'm making a app and I'm unable to fire a promise, I breaked the code to the a simple example that still does not work, I'm using EasyPHP...
ajaxDialog = function( destiny ) {
// Promise to let me know when complete
return $.ajax({
url: destiny,
dataType: 'json',
}).promise();
};
teste = ajaxDialog('data.json');
teste.done( function() { alert("sadasassa"); })
Upvotes: 0
Views: 2227
Reputation: 1328
Check if this would work:
return $.ajax({
url: destiny,
dataType: 'json',
}).promise(function(){alert("This is a test");});
I don't know what would that change but everything is worth trying!
Upvotes: 0
Reputation: 664297
a simple example that still does not work
The JavaScript works well. Probably your server does not work and does not return a JSON document from the data.json
url.
Use
teste.done( function() {
alert("sadasassa");
}).fail( function(x, s, e) {
alert(s+": "+e);
});
and debug with the Networks
tab in your browser devtools what is happening.
Upvotes: 0
Reputation: 92274
Your ajax is failing and going to the fail handler. If you do the following you will see an alert.
// This does get called
teste2.fail( function() { alert("sadasassa"); });
Here's a jfiddle that proves that if you do reach your server, it gets called http://jsfiddle.net/L6bJ2/367/
$(function() {
ajaxDialog = function( destiny ) {
// Promise to let me know when complete
return $.ajax({
url: '/echo/json/',
dataType: 'json',
}).promise();
};
teste2 = ajaxDialog('data.json');
teste2.done( function() { alert("sadasassa"); });
});
Upvotes: 2
Reputation: 14719
try this:
when(ajaxDialog('data.json')).then(function() { alert("aaaa"); });
Upvotes: 0