Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中等待服务器响应_Javascript_Python_Json_Flask - Fatal编程技术网

在Javascript中等待服务器响应

在Javascript中等待服务器响应,javascript,python,json,flask,Javascript,Python,Json,Flask,我使用Flask和JSON在python和javascript之间进行通信。我希望程序在切换选项卡之前等待服务器的响应。这是我的javascript代码 window.onload = function() { // setup the button click document.getElementById("submit").onclick = function() { doWork()

我使用Flask和JSON在python和javascript之间进行通信。我希望程序在切换选项卡之前等待服务器的响应。这是我的javascript代码

            window.onload = function() {
// setup the button click
                document.getElementById("submit").onclick = function() {
                    doWork()
                };
            }

            function doWork() {
                $.post("http://127.0.0.1:5000/", JSON.stringify([document.getElementById("URL").value, document.getElementById("term").value, document.getElementById("pages").value]), function(){

                });
                // stop link reloading the page
             event.preventDefault();
             //HERE: Wait for response from server
             window.location.href = "http://127.0.0.1:5000/results";
            }
        </script>
window.onload=function(){
//设置按钮单击
document.getElementById(“提交”).onclick=function(){
嫁妆
};
}
函数doWork(){
$.post(”http://127.0.0.1:5000/stringify([document.getElementById(“URL”).value,document.getElementById(“term”).value,document.getElementById(“pages”).value]),函数(){
});
//停止链接重新加载页面
event.preventDefault();
//此处:等待服务器的响应
window.location.href=”http://127.0.0.1:5000/results";
}

这是否可能使用Flask和JSON,或者我必须使用其他东西?

这就是ajax调用的承诺。。。。将该行放入空函数
event.preventDefault()事件未定义请查看jQuery文档:。具体来说,请注意“success”参数。这是一个成功响应返回时的回调。我不太明白你所说的等待响应是什么意思。尝试将success函数块放在ajaxpost调用中,不要在其中放入任何内容,即使在响应之后,如果您没有任何操作,它也会保持相同的状态吗?
            window.onload = function() {
// setup the button click
                document.getElementById("submit").onclick = function() {
                    doWork()
                };
            }

            function doWork() {
                $.post("http://127.0.0.1:5000/", JSON.stringify([document.getElementById("URL").value, document.getElementById("term").value, document.getElementById("pages").value]), function(){

                });
                // stop link reloading the page
             event.preventDefault();
             //HERE: Wait for response from server
             window.location.href = "http://127.0.0.1:5000/results";
            }
        </script>