Axios javascript。我需要每隔100毫秒通过setInterval js从客户端检查一次服务器

这是客户端。我确实使用Axios从客户端请求到本地主机。我希望服务器每500毫秒响应一次。

setInterval(function () {
    axios.get('http://127.0.0.1:8000/progress').then(function (data) {
        console.log(data)
    })
},500)

这是服务器端/服务器应该只发送一个文本。而且它不起作用。为什么?

Route::get("/progress",function() {
    return "text";
});

同时,我确实请求另一条路线,并在文件上传时等待响应。并且SetInterval仅在此发布请求之后才能工作。为什么?

axios.post('http://127.0.0.1:8000/test',formData,{
        headers: {
            'Content-Type': 'multipart/form-data'
        },onUploadProgress: function (progressEvent) {
            this.uploadPercentage = parseInt(Math.round((progressEvent.loaded * 100) / progressEvent.total));
        }.bind(this)
    }).then(function (data) {
        console.log("Image Upload");
    })
    .catch(function (data) {
        console.log(data);
    });
},

那是行不通的。为什么?

fszxg 回答:Axios javascript。我需要每隔100毫秒通过setInterval js从客户端检查一次服务器

使用相对URL,并确保在加载A​​xios的位置包含该URL,例如import org.apache.commons.lang.StringEscapeUtils; public class Escape { public static void main(String[] args) { System.out.println(StringEscapeUtils.unescapeXml("Arsenal's trip to Vitoria a 'more difficult' test than reverse Europea League tie,warns hosts' coach")); } } ,并记录响应数据,而不是响应对象本身

app.js

希望这会有所帮助

本文链接:https://www.f2er.com/3152961.html

大家都在问