में AJAX पोस्ट वैरिएबल पढ़ना मैं अपने नोड एप्लिकेशन में AJAX पोस्ट के लिए जो मूल्य भेज रहा हूं उसे प्राप्त करने का प्रयास कर रहा हूं। एक गाइड के रूप this post का उपयोग करना, मैं अब तक इस राशि:नोड.जेएस (एक्सप्रेस के साथ)
नोड में: AJAX तरफ
var express = require('express');
var app = express();
var db = require('./db');
app.get('/sender', function(req, res) {
res.sendfile('public/send.html');
});
app.post('/send_save', function(req, res) {
console.log(req.body.id)
console.log(req.body.title);
console.log(req.body.content);
res.contentType('json');
res.send({ some: JSON.stringify({response:'json'}) });
});
app.listen(3000);
पर:
$('#submit').click(function() {
alert('clicked')
console.log($('#guid').val())
console.log($('#page_title').val())
console.log($('#page-content').val())
$.ajax({
url: "/send_save",
type: "POST",
dataType: "json",
data: {
id: $('#guid').val(),
title: $('#page_title').val(),
content: $('#page-content').val()
},
contentType: "application/json",
cache: false,
timeout: 5000,
complete: function() {
//called when complete
console.log('process complete');
},
success: function(data) {
console.log(data);
console.log('process sucess');
},
error: function() {
console.log('process error');
},
});
})
यह समस्या है कि मैं req.body नहीं कर सकता है .id (और शीर्षक या सामग्री जैसे किसी अन्य मूल्य), मुझे यह त्रुटि नोड में मिल रही है:
TypeError: Cannot read property 'id' of undefined
अगर मैं टिप्पणी करता हूं ई कॉल हालांकि, AJAX सफल है। मै खो गया हूँ। क्या मैं कुछ भूल रहा हूँ?
मैं एक ही समस्या है - उपयोग की कोशिश 'परम ('postVariableName') ' – fider