Getting the ajaxForm success error message to show
Posted: 06 January 2011 04:27 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

Hello,

I looked at the documentation for jQuery Form as well as safecracker but I can’t seem to get the success callback function to fire. I was able to get the simple function to fire like so…

$('#updatePageSite').ajaxForm(function(){
alert(
"foobar");
}); 


But that looks like it’ll go off no matter if it was successfull or not.


So I tried running the code provided here in the documentation using the Options object. But it just won’t work

$('#updatePageSite').ajaxForm({
                dataType
'json',
                
success: function(data{
                    
if (data.success{
                        alert(
'You successfully added a new entry with entry_id '.data.entry_id)
                    } 
else {
                        alert(
'Failed with the following errors: '+data.errors.join(', '));
                    
}
                }
            }
); 

It never fires. I can’t figure out if this is something wrong with jQuery Form or safecracker, or something on my end.

[ Edited: 06 January 2011 04:34 AM by Dave Joyce ]
Profile
 
 
Posted: 06 January 2011 04:28 AM   [ Ignore ]   [ # 1 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

P.S. I tried many times to submit this post, but it was not allowed because the computer thought it might be spam so it was discarded. I narrowed it down to the “alert” keyword that was throwing it off. Not sure why that would raise a flag as spam.

Profile
 
 
Posted: 06 January 2011 04:32 AM   [ Ignore ]   [ # 2 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

try alert() instead of echo() and see if that works?

Profile
 
 
Posted: 06 January 2011 04:35 AM   [ Ignore ]   [ # 3 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

it’s the forum that’s not letting me post “alert” in that code block. I just put in alert with spaces instead of echo and that seems to be accepted.

Edit: ok, weird. after I edited that with spaces in the alert, it removed the spaces and it displays correctly confused

[ Edited: 06 January 2011 04:38 AM by Dave Joyce ]
Profile
 
 
Posted: 06 January 2011 04:36 AM   [ Ignore ]   [ # 4 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Ah, gotcha smile

Are you getting any javascript errors in your console?

Profile
 
 
Posted: 06 January 2011 04:42 AM   [ Ignore ]   [ # 5 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

Just a warning about resource (”/?ACT=jquery”) being interpreted as script but transferred with MIME type text/html.

The form works great too. I just can’t get the callback function to fire.

Profile
 
 
Posted: 06 January 2011 04:45 AM   [ Ignore ]   [ # 6 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

can you do this and see what shows up in your console?

$('#updatePageSite').ajaxForm({
                success
: function(data{
                    window
.console.log(data);
                
}
            }
); 
Profile
 
 
Posted: 06 January 2011 04:57 AM   [ Ignore ]   [ # 7 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

I’m in safari with the error console up and nothing happens. It doesn’t get far enough to even run that command.

In Firefox I got an error that window.console was undefined. But the alerts don’t work in firefox either :(

Profile
 
 
Posted: 06 January 2011 05:01 AM   [ Ignore ]   [ # 8 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

ok, correction. I’m sorry. The log contains all the generated html on my page =/

Profile
 
 
Posted: 06 January 2011 05:05 AM   [ Ignore ]   [ # 9 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Do you have json=“yes” in your form?

Profile
 
 
Posted: 06 January 2011 05:09 AM   [ Ignore ]   [ # 10 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-02

[Slaps hand on head]

I totally missed that. It works beautifully now! Thanks a ton Rob =D

Profile
 
 
Posted: 06 January 2011 11:01 PM   [ Ignore ]   [ # 11 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Glad you got it working smile

Profile