如何解决Django ajax 帖子在网络主机上引发 500 错误,但在本地主机上运行
我可以在本地服务器上使用 AJAX 发送 JSON 数据,但是,当我在网络服务器上运行同一个站点时,ajax 帖子抛出 500(内部服务器错误)。 urls.py
urlpatterns = [
path('recievejson/',views.recievejson,name='recievejson'),]
视图.p
@csrf_exempt
def recievejson(request):
if request.method == 'POST': # This condition is satisfied when hosted on localhost.
import json
print("DATA RECIEVED")
print(request.body)
else: # This condition is satisfied when onsted on web server.
message = "Data not recieved"
return JsonResponse({"message": 'http://domain name com/static/text/'+message})
AJAX:
$.ajax({
url: "/recievejson",type: "POST",data: data,processData: false,contentType: "application/json; charset=UTF-8",success: function(data) {
console.log("SUCCESS");
},error: function(data){
console.log("fail");
}
});
如何解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)