【发布时间】:2013-12-26 15:30:10
【问题描述】:
我正在使用 Phonegap 创建一个 android 移动应用程序,所以我决定使用 jQuery 移动应用程序。服务器端将由 node.js 应用程序处理。
在客户端,我让 javascript 发送一个 POST 请求:
function validate() {
//alert($('#username').val());
var uname = $('#username').val() ;
var pword = $('#password').val() ;
$.ajax({
type : "POST",
dataType: "jsonp",
jsonpCallback: "responding",
url : "http://localhost:8888/authenticate",
data : { username: uname , password : pword },
success : function(data) {
alert(data);
},
error : function(jqXHR, textStatus, errorThrown) {
alert("Error, status = " + textStatus + ", " + "error thrown: " + errorThrown);
}
});
}
在服务器端,节点使用
function authenticate(request, response) {
console.log("Request handler 'upload' was called.");
console.log(request);
response.writeHead(200, {
"Content-Type" : "text/plain"
});
response.write('responding(\'{"message": "Dummy Reply!"}\')');
response.end();
}
当我绑定 console.log(request) 如你所见时,在控制台中,连同很多东西,我得到了这个..
url: '/authenticate?callback=responding&username=foo&password=bar&_=1388071403212', 方法:'GET',
POST 方法在服务器端是如何变成 GET 方法的??
您还可以告诉我如何在节点端的 POST 请求中获取参数。
【问题讨论】:
标签: javascript android node.js jquery jquery-mobile