node.js에 대한 작은 아약스 실시간 검색을 작성하려고합니다.ajax node.js/express 서버로 GET 호출
$('#words').bind('keyup', function(){
getMatchingWords($('#words').val(), function (data){
console.log('recieved data');
console.log(data);
$('#ajaxresults').show();
});
});
function getMatchingWords(value, callback) {
$.ajax('http://127.0.0.1:3000/matchword/' + value + '/', {
type: 'GET',
dataType: 'json',
success: function(data) { if (callback) callback(data); },
error : function() { if (callback) callback(null); }
});
}
여기 내 서버 측 경로 인도 표준시 :
app.get('/matchword/:value', function(req, res) {
console.log(req.params.value);
res.writeHead(200, {'content-type': 'text/json' });
res.write(JSON.stringify({ test : 'test'}));
res.end('\n');
});
작동을하지만 난 모든 데이터를받을하지는 우선 여기 내 클라이언트 측 코드입니다. 콜백 함수의 데이터는 항상 null입니다. 그래서 내가 뭘 잘못하고 있니? 도움을위한 thx
이것이 node.js와 다른 점은 확실하지만 'content-type'은'Content-Type'이 아니어야합니까? –
아니요, –