Python Flask框架下不通過表單發送而選擇單獨發送數據到後臺服務器的方法

參考:https://www.jb51.net/article/144819.htm

數據單獨發給後端:

var ip = $(this).parent().prev().prev().prev().prev().text();
data_tmp = {'ip':ip, 'text':"success for ajax"};  // data to send to server.
$.post('/js_call', data_tmp, function(data){alert(data)});

其中$.post('/js_call', data_tmp, function(data){alert(data)})中'/js_call'是發送數據的地址(定義了數據被髮往何處),function(data){alert(data)})是post發生時調用的函數,該函數會彈出一個警告窗,改成function(data){}警告窗就消失了。

後端處理程序:

@app.route('/js_call', methods=['GET', 'POST'])
def js_call():  
   print request.values['ip']  
   print request.values['text']  
   # to send the command by ssh : os.system("ssh user@host \' restart(command) \' ")  
   return 'ok!!!!'

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章