嘗試了很多示例,花費了大量時間,但它只是沒有解決。如果有人能夠在這種情況下幫助我,那將是非常棒的。所以,我想要做的是從p#lessonText.lesson(style='margin-left:1%;' name='desc') #{item.description}
獲得價值我需要#{item.description}
傳遞給我的服務器端。從客戶端到服務器端節點的傳輸值js
這是在服務器端的我的客戶端代碼
form#myForm()
.container
ul
each item, index in items
#allLessons.container
.lessonsWrap
h3.lesson #{index+1} . Lesson |
p#lessonText.lesson(style='margin-left:1%;' name='desc') #{item.description}
button#butPam.btn.btn-primary(type='submit') Begin
.lesDescription
p(style='margin-left:1%;') Lecturer: #{item.author}
p(style='margin-left:1%;') Level: #{item.level}
script.
$('#myForm').on('submit', function(event){
var createVar = $('#lessonText').text();
alert(createVar);
$.ajax({
url: '/qVal',
method: 'post',
contentType: 'application/json',
data: JSON.stringify({desc: createVar.val()}),
async: true,
success: function(response){
console.log(response);
}
})
});
這裏現在我只是想看看,如果我可以創建一個變量,它是從客戶端通過。
router.post('/qVal', function(req,res){
console.log("server");
var description = req.body.desc;
console.log(typeof(desc));
console.log(desc);
});
也許我錯了使用方法,也許我應該使用GET方法呢? 重要的是說,它看起來我的router.post不起作用。當我寫console.log(「服務器」),在控制檯單詞「服務器」沒有出現。
所以你的'console.log(「服務器」);'被解僱? – gaganshera
不是,它不 –
檢查您的瀏覽器的ajax調用的網絡選項卡是否觸發,並檢查請求中的URL。我猜可能是/ qVal路徑 – gaganshera