Kindly let me know how to consume django api method using jquery ajax call, because when I try to access directly URL am getting response, however when I send request using jquery ajax call, it goes to error function.
Dajango code:
def rain_api(request):
data = {}
data['test'] = 'hello'
return HttpResponse(json.dumps(data), content_type = "application/json")
JQuery code:
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);
}
})
Try this out
$.ajax({
type: 'POST',
url: 'http://ipaddress/raindata',
processData: true,
dataType: 'json',
success: function(data ) {
console.log("Success")
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.