[英]django json response and ajax call
請讓我知道如何使用jquery ajax調用來使用django api方法,因為當我嘗試直接訪問URL時會得到響應,但是當我使用jquery ajax調用發送請求時,它將轉到錯誤功能。
Dajango代碼:
def rain_api(request):
data = {}
data['test'] = 'hello'
return HttpResponse(json.dumps(data), content_type = "application/json")
jQuery代碼:
requestURL="http://ipaddress/raindata";
$.ajax({
url: requestURL,
dataType: "json",
success:function(result){
console.log(result)
},
done:function(result){
console.log(result)
},
error:function(error){
console.log(error);
}
})
試試看
$.ajax({
type: 'POST',
url: 'http://ipaddress/raindata',
processData: true,
dataType: 'json',
success: function(data ) {
console.log("Success")
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.