0

I'm using an ajax call to my API created with Piston/Django. I tested that the API URLs are correct by directly typing them in the browser.

However, the ajax request always triggers the error callback function but returns an undefined error. I think the problem is somewhere inside my ajax call. Could anyone help me? Thanks a lot.

Here is my javascript:

    $("#delete_req").click(function(event){
    //PUTs data, saving new permissions
    alert("delete_req");
    event.preventDefault();
    $.ajax({
      url:"{{SITE_URL}}requests/api/manage/disc={{vialogue.discussion_id}}&puser={{req.userid}}&acc=0/",
      type:'GET',
      success: function(data, textStatus, jqXHR){
        location.reload( true );
      },
      error: function(jqXHR, textStatus, errorThrown){
        alert(errorThrown);
        alert(textStatus);
        alert("There was an error deleting this request. Please try again or contact us for help.")
     }
    });

    });
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Wei An
  • 1,779
  • 4
  • 13
  • 18
  • Please don't just add "Solved" to the title, but provide the solution in an answer and accept it. – vikingosegundo Jun 16 '11 at 13:10
  • I have this exact same problem, but I cannot find the solution in your post. Could explain what you mean by "I found out I define 'req' after using it"? – Kevin Jul 07 '12 at 16:28

2 Answers2

0

In django 1.2.5 and 1.3, Ajax form submits expect a csrf token.

lprsd
  • 84,407
  • 47
  • 135
  • 168
0

Are you sure that's the correct URL? It has a very strange structure. I would expect the elements that look like GET parameters to actually be GET parameters:

{{SITE_URL}}requests/api/manage/?disc={{vialogue.discussion_id}}&puser={{req.userid}}&acc=0

Does it work if you make that change?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895