2012-03-20 79 views
-1

1˚ - 客戶端:+的NodeJS + ExpressJS玉+後沒有呈現

$.ajax({ 
    type: 'POST', 
    data: data, 
    url: '/someposturl', 
    success: function (data) { 
     console.log('success'); 
     // $('body').html(data); // i don't want it, but if not so, nothing happens (render) 
    } 
}); 

2˚ - 服務器:

app.get('/criptografar', function (req, res) { 
    console.log(req.something); 
    res.render('somepage', { 
     somevar: withsomevalue 
    }); 
    //-I want this to work like a normal post 
}); 

3˚ - 客戶端 - > 'SomePage的' - 沒有這個未呈現在客戶端:

$('body').html(data); // i don't want it, but if not so, nothing happens (render) 

或本

$('html').html(data); // i don't want it, but if not so, nothing happens (render) <- Jade Layout error. 
+2

而應該發生什麼?您正在進行ajax調用,並且您可以清楚地看到服務器響應數據。你知道ajax是什麼嗎? :)如果你想讓它像普通的POST一樣工作,你可以例如從服務器返回URL並執行'location.href = url;'。 – freakish 2012-03-20 15:27:57

+0

下次請正確格式化您的代碼;而其他人很可能會很快做到這一點,讓他們做一些你可以輕鬆做到的事情也不好。 – ThiefMaster 2012-03-20 23:46:59

+0

你應該使用** app.post(**代替app.get( – 2012-10-15 07:18:41

回答

-1

因爲您從客戶端撥打$.ajax。 如果從服務器端

叫它做一個頁面調用從服務器端的URL它的工作好,你應該添加到您的形式

form(role="form" method="POST") 

請參考這個問題。 Express.js Won't Render in Post Action

+0

)雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的基本部分,並提供鏈接以供參考。如果鏈接頁面發生變化,可能會失效 – 2014-10-12 21:08:07

+0

好的,注意@ Rory-McCrossan – 2014-10-13 11:24:30