samedi 18 avril 2015

how to send variables via ajax json format and how receive this data in python flask

I want to send the contents of the variables via ajax json format, and recover data in python but still I did not managed to fare or sending or retrieving the data.I need help please.





function deconnectmac(){

var essi = prompt("Please enter essi!!");
var tab = prompt("Please enter the tab!!");
var jsonObj = [];
var obj = {};
obj["tab"]=tab;
obj["essi"]=essi;
jsonObj.push(obj);
console.log(jsonObj);
$jsonObj=JSON.stringify(jsonObj);
if (tab != null) {
if(essi!= null){

$.ajax({
type: 'POST',
url: '/deconnect',
data:{ data: jsonObj },
dataType: 'text',
success: function(text) {
if (text === "success") {
alert("success");
} else {
alert(text);
}
},
error: function(error){

console.log(error);
}

});

}}

}






@APP.route('/deconnect',methods=['POST'])
def deconnect():
donne_request=json.loads(request)

print donne_request
return "success"



Aucun commentaire:

Enregistrer un commentaire