I've thought about your post some more and I think this might actually
be ok. Considering that right now the only callback that is fired is
the success callback we can safely assume that people who are using
this method don't actually care about the error state - thus if we
pass in the normal error callback the page will still break (albeit in
a different manner).

Thus if you wanted to make proper use of the $.get or $.post with the
dual-callback functionality you would have to do:

$.get("someurl", function(data){
  if ( typeof data === "string" ) {
    // got results
  } else {
    // got error
  }
});

Another option could be a modified error callback and actually have it
work like this:

$.get("someurl", function(data, errorMessage){
  if ( data ) {
    // got results
  } else {
    // got error
    alert( errorMessage );
  }
});

Thoughts on this?

--John



On Sun, Nov 8, 2009 at 12:29 PM, Mr Speaker <mrspea...@gmail.com> wrote:
> The $.post and $.get are really handy, but seem limited in their use
> for serious work because you can't tell if they fail (can you? I mean,
> besides the global error handler?).
>
> I couldn't find any discussion on this, it would be useful if you
> could just call the same callback method for either success or error
> and let the user play with the result:
>
> post: function( url, data, callback, type ) {
>        ...
>        return jQuery.ajax({
>                type: "POST",
>                url: url,
>                data: data,
>                success: callback,
>                error: callback,  <-- same function
>                dataType: type
>        });
>
> This would be especially useful for $.post where it's usually pretty
> important that you know that an update has occurred. In the
> documentation the callback code has this comment:
> // NOTE: Apparently, only "success" is returned when you make
> // an Ajax call in this way. Other errors silently fail.
>
> So I guess there is a reason for not doing this... it would break
> existing code for people who just checked for ANY return value, and I
> suppose it complicates the simple $.post function a little - but it
> would give these helper functions more "real world" uses.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "jQuery Development" group.
> To post to this group, send email to jquery-...@googlegroups.com.
> To unsubscribe from this group, send email to 
> jquery-dev+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/jquery-dev?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-...@googlegroups.com.
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en.


Reply via email to