您好,我正在使用 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 成功响应吗?os.system()编辑:我已经替换了里面的命令ifconfig,mkdir它一切正常并得到了成功响应。该命令roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/maps/mapname.yaml启动一个节点并且永远不会用完。那么有没有办法即使节点正在运行也可以返回成功响应?
2 回答
![?](http://img1.sycdn.imooc.com/533e4d510001c2ad02000200-100-100.jpg)
慕仙森
TA贡献1827条经验 获得超8个赞
我觉得您只想启动启动文件,而不是等到它终止。如果是这种情况,那么您需要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)
![?](http://img1.sycdn.imooc.com/5333a1d100010c2602000200-100-100.jpg)
饮歌长啸
TA贡献1951条经验 获得超3个赞
你的 success 函数位置错误,试试这个。
$.ajax({
url: '/test',
type: 'POST',
data: new_freq
},
success: function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
})
添加回答
举报
0/150
提交
取消