Ajax调用Django(Piston)API总是失败

时间:2021-05-01 19:21:01

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.

我正在使用对使用Piston / Django创建的API的ajax调用。我通过在浏览器中直接输入来测试API URL是否正确。

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.

但是,ajax请求始终会触发错误回调函数,但会返回未定义的错误。我认为问题出在我的ajax调用中。谁能帮助我?非常感谢。

Here is my javascript:

这是我的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.")
     }
    });

    });

2 个解决方案

#1


0  

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

在django 1.2.5和1.3中,Ajax表单提交了一个csrf令牌。

#2


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:

你确定这是正确的URL吗?它有一个非常奇怪的结构。我希望看起来像GET参数的元素实际上是GET参数:

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

Does it work if you make that change?

如果你做出改变,它会起作用吗?

#1


0  

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

在django 1.2.5和1.3中,Ajax表单提交了一个csrf令牌。

#2


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:

你确定这是正确的URL吗?它有一个非常奇怪的结构。我希望看起来像GET参数的元素实际上是GET参数:

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

Does it work if you make that change?

如果你做出改变,它会起作用吗?