weixin_33716557 2013-11-01 19:42 采纳率: 0%
浏览 91

Ajax与node.js / jade

I'm searching for a way to use ajax running on node.js, express and jade as template-engine without routing to subpages. I read this: Node, Express, Ajax, and Jade Example

But this doesn't work for me. I don't want to make a route to a partial part of page, so the user could access the partial page. I just want to serve a convertet jade file in a part of the website.

I think about something like this:

$( ".trigger" ).on( "click", function() {
    $( ".result" ).load( "ajax/test.jade" );
});

How could I do this without setting a route in node.js so the user could access the subpage without accessing the whole page.

Thank you for your answers.

  • 写回答

4条回答

  • 三生石@ 2013-11-01 20:01
    关注

    (Still requires a route but) You could set up a route that only provides a valid response if it is an ajax request, and a 4xx if otherwise

    app.get('/path', function(req, res) {
      if(req.xhr)
      {
        ...
      }
    });
    

    req.xhr Express docs.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法