SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    May 2008
    Location
    Missouri, USA
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Jquery - Pipe Original Data to Ajax Fail event

    Hello, I have a scenario i'm trying to understand so I can implement it in my jquery code.

    I have a series of jquery ajax calls that use this function:
    Code:
    callService = function(url,data){
    		var request = $.ajax({
    			url: url,
    			data: data,
    			dataType: "jsonp",
    			jsonp : "callback",
    			jsonpCallback: "jsoncallback",
    			error:function (xhr, ajaxOptions, thrownError){
    				console.log(xhr);
    				DisplayError({error:thrownError, data});
    			}
    		});
    	};
    I use this function to async load multiple components in my ui. When I have a success everythings work perfectly because the response contains all the data I need. But, when "error" is triggered I run into a problem because it does not return any of the original data. I need the original data in order to associate the ajax call to a specific component in my ui.

    I found the pipe function in jquerys documentation and i'm trying to understand how to use it. What I would like to do is 'pipe' the data variable used in the ajax request into the error function. I'm a little confused on the syntax to do this and would appreciate some help or suggestions for better approaches.

    Thanks for your help.
    Follow Me On Twitter: BryceRay

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    It looks like you're trying to pass in a single value to an object without setting a key, you might want to try:

    Code javascript:
    DisplayError({error:thrownError, "data":data}); //note the key:value syntax
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •