Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.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
Jquery 在node.js中的ajax post之后不会呈现HTML页面_Jquery_Ajax_Node.js_Express - Fatal编程技术网

Jquery 在node.js中的ajax post之后不会呈现HTML页面

Jquery 在node.js中的ajax post之后不会呈现HTML页面,jquery,ajax,node.js,express,Jquery,Ajax,Node.js,Express,我正在使用express.js。我想做的是在单击表元素后重定向到html页面。当前,输出是HTML source console.log(而不是重定向,然后作为HTML页面插入) 我的点击功能如下(ajax帖子) 我在chrome javascript控制台中获得了HTML输出,但在浏览器中我看不到它重定向到hello.HTML。您的res.redirect('hello.HTML')指令对AJAX请求没有影响。AJAX是异步的,因此请求将发送到服务器,响应将返回到浏览器,由JavaScript

我正在使用express.js。我想做的是在单击表元素后重定向到html页面。当前,输出是HTML source console.log(而不是重定向,然后作为HTML页面插入)

我的点击功能如下(ajax帖子)

我在chrome javascript控制台中获得了HTML输出,但在浏览器中我看不到它重定向到hello.HTML。

您的
res.redirect('hello.HTML')
指令对AJAX请求没有影响。AJAX是异步的,因此请求将发送到服务器,响应将返回到浏览器,由JavaScript进行解释

要在AJAX请求后重定向到另一个页面,您需要在
控制台.log('processcomplete')
指令下提供额外指令(
window.location.replace(
hello.html')
指令。

您的
res.redirect('hello.html')
指令对AJAX请求没有影响。AJAX是异步的,因此请求将发送到服务器,响应将返回到浏览器,由JavaScript进行解释


要在AJAX请求后重定向到另一个页面,您需要在
console.log('process complete')
指令下提供额外指令(
window.location.replace(
)~~ web javascript

$.ajax({
    url: '/test',
    type : 'POST',
    data: data,
    success : function(ret){
        document.write(ret);
    },
    error: function(err){
        document.write(err.responseText);
    }
});
服务器代码是

app.post('/test$',function(req,res,next){
     if(req.body.xxx != null){
        res.render('test',{xxx:xxx})
     }else{
        var err = {};
        err.status = 403;
        err.message = 'not allow';
        next(err);
     }
});

app.use(function(err, req, res, next) {
   res.locals.message = err.message;
   res.render('error');
});

你可以试试……

我也有同样的问题,我找到了另一种解决方法~~ web javascript

$.ajax({
    url: '/test',
    type : 'POST',
    data: data,
    success : function(ret){
        document.write(ret);
    },
    error: function(err){
        document.write(err.responseText);
    }
});
服务器代码是

app.post('/test$',function(req,res,next){
     if(req.body.xxx != null){
        res.render('test',{xxx:xxx})
     }else{
        var err = {};
        err.status = 403;
        err.message = 'not allow';
        next(err);
     }
});

app.use(function(err, req, res, next) {
   res.locals.message = err.message;
   res.render('error');
});

您可以试试……

我想您应该在
$.ajax
请求中插入
async:false
。然后,如果愿意,您可以删除
超时。
。异步不走运:false。我可以在控制台日志中看到呈现的html页面,然后是“流程成功”和“流程完成”消息。我想您应该在
$.ajax
请求中插入
async:false
。然后,如果愿意,您可以删除
超时。
。异步不走运:false。我可以在我的控制台日志中看到呈现的html页面,然后是“流程成功”和“流程完成”消息。