1

I have a part of my backbone application that requires a user confirmation when I try to insert a value through my WebApi.

I have this code:

@xhr = $.post '/api/entity/create', @data

@xhr.done (resp) =>
    if @xhr.status == 202
        # Some code for confirmation box
         @data.Force = true
         @xhr = $.post '/api/entity/create', @data # Problem is here

@xhr.fail (resp) =>
    # Code for error

When I force the insertion I don't go through @xhr.done after my WebApi call

Do you have any clue why it doesn't work?

Thanks

1 Answer 1

1

That's because that's a new @xhr, and the callbacks are attached to the old. You can move it to another method and reuse it (I imagine you have a class around the code):

post: ->

  @xhr = $.post '/api/entity/create', @data

  @xhr.done (resp) =>
    if @xhr.status == 202
      # Some code for confirmation box
      @data.Force = true
      @post()

  @xhr.fail (resp) =>
    # Code for error
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.