开发者

Ajax call for a Django(Piston) API always fail

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, te开发者_开发百科xtStatus, errorThrown){
        alert(errorThrown);
        alert(textStatus);
        alert("There was an error deleting this request. Please try again or contact us for help.")
     }
    });

    });


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜