I am developing a simple web app based on the Python framework Flask. Here I am trying to get a JSON response from a POST AJAX request. Below code shows my AJAX call:
var hotel=$( "#listHotel option:selected" ).val();
$.ajax({
url: "/getHotels",
contentType: "application/xml; charset=utf-8",
data: JSON.stringify({'hotel':hotel}),
type: "POST",
success: function(response){
var r= JSON.parse(response);
var rating =r.message
alert(rating);
$("#rate").html("Ratings : "+rating);
$("#rate").show('slow');
console.log(response);
},
error: function(error){
alert(response);
console.log(error);
}
});
And this is my Python code
def getHotels():
try:
_hotel = {"value": request.json['hotel']}
print _hotel
hotel= _hotel["value"]
print hotel
But I am not getting the JSON object. I tried my best. Please help me to get the JSON object / value.