从Chrome扩展程序到django的Ajax POST请求失败了400

时间:2018-02-16 14:39:09

标签: django nginx google-chrome-extension gunicorn

我的服务器(AWS实例)上有一个运行在Nginx + Gunicorn上的Django REST API,我正在尝试使用Ajax从Chrome扩展中调用此API。我不能让它发挥作用。 API本身似乎工作正常 - 我可以使用cURL发出类似的请求,它可以正常工作。但是,当我尝试从扩展程序执行此操作时,我收到400错误。目前没有身份验证,我正在调用的网站和Django应用程序都在https上运行(起初我认为这可能是一个问题),我将它们都添加到permissions manifest.jsonbackground.js 1}}。我的电话(来自$.ajax({ type: "POST", crossDomain: true, cache: false, url: 'https://**************/', data: JSON.stringify(collectedData), success: function(data, textStatus, xhr) { collectedData = []; server_response = xhr.status; }, error: function(xhr, textStatus, error) { server_response = xhr.status; }, dataType: "json" }).always(function(){ sendResponse({ status: server_response }); }); )看起来像这样:

SELECT 
  YEAR(c.created_at) 'YEAR',
    COUNT(IF(MONTH(c.created_at) = 1 and k.created_at > '2017-02-31', c.id, NULL))'January',
    COUNT(IF(MONTH(c.created_at) = 2 and k.created_at > '2017-03-28', c.id, NULL)) 'February',
    COUNT(IF(MONTH(c.created_at) = 3 and k.created_at > '2017-04-31', c.id, NULL)) 'March',
    COUNT(IF(MONTH(c.created_at) = 4 and k.created_at > '2017-05-30', c.id, NULL)) 'April',
    COUNT(IF(MONTH(c.created_at) = 5 and k.created_at > '2017-06-31', c.id, NULL)) 'May',
    COUNT(IF(MONTH(c.created_at) = 6 and k.created_at > '2017-07-31', c.id, NULL)) 'June',
    COUNT(IF(MONTH(c.created_at) = 7 and k.created_at > '2017-08-31', c.id, NULL)) 'July',
    COUNT(IF(MONTH(c.created_at) = 8 and k.created_at > '2017-09-31', c.id, NULL)) 'August',
    COUNT(IF(MONTH(c.created_at) = 9 and k.created_at > '2017-10-31', c.id, NULL)) 'September',
    COUNT(IF(MONTH(c.created_at) = 10 and k.created_at > '2017-11-31', c.id, NULL)) 'October',
    COUNT(IF(MONTH(c.created_at) = 11 and k.created_at > '2017-12-31', c.id, NULL)) 'November',
    COUNT(IF(MONTH(c.created_at) = 12 and k.created_at > '2018-01-31', c.id, NULL)) 'December'
FROM
    companies c join employees e on c.id=e.company_id
    join (select employee_id,min(c.created_at) created_at from contributions c join employees e
    on c.employee_id=e.id group by e.company_id) k 
    on e.id=k.employee_id
WHERE
    c.created_at between '2017-01-01' and '2017-12-31'
GROUP BY YEAR(c.created_at) 

我的想法已经不多了。我做错了什么?

0 个答案:

没有答案