![](/img/trans.png)
[英]jQuery ajax call is returning response data as String instead of Object
[英]AJAX Jquery call not returning response
嗨,我正在使用 Jquery 對 Flask 服務器運行 AJAX 調用,但是一旦我運行,它就不會返回成功響應消息:
os.system("roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/maps/"+mapname+".yaml")
這是我提出的要求:
$.ajax({
url: '/test',
type: 'POST',
data: new_freq,
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
})
燒瓶服務器代碼,
@app.route("/test" , methods=['POST'])
def test():
mapname = request.get_data().decode('utf-8')
os.system("roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/maps/"+mapname+".yaml")
return(mapname)
有人知道如何返回 AJAX 成功響應嗎?
編輯:我已經用ifconfig
和mkdir
替換了os.system()
的命令,它一切正常並得到了成功響應。這個命令roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/maps/mapname.yaml
啟動一個節點並且從不運行out.So 有沒有辦法即使節點正在運行也可以返回成功響應?
你的成功函數位置錯誤,試試這個。
$.ajax({
url: '/test',
type: 'POST',
data: new_freq
},
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
})
我覺得您只想啟動啟動文件,而不是等到它終止。 如果是這種情況,那么您想在后台啟動roslaunch
命令, roslaunch
它與正在運行的 python 進程分離:
import subprocess
@app.route("/test" , methods=['POST'])
def test():
mapname = request.get_data().decode('utf-8')
subprocess.Popen(["roslaunch", "turtlebot3_navigation", "turtlebot3_navigation.launch", "map_file:=$HOME/maps/"+mapname+".yaml"])
return(mapname)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.