我是 jQuery mobile 1.4.3 和 javascript 的新手,我正在尝试注册一个新用户,向 Web 服务发送 AJAX Post 调用,但我迷路了...
用户注册必须将以下 JSON 发送到 Web 服务:
{
"userName": "sample string 1",
"email": "sample string 2",
"password": "sample string 3",
"confirmPassword": "sample string 4",
"name": "sample string 5",
"deviceId": "sample string 6"
}
网络服务 URL:http://company.ac-web-systems.eu/api/account/register
我的 AJAX 代码:
var formData = {
"userName": "user1",
"email": "email@mail.com",
"password": "123456",
"confirmPassword": "123456",
"name": "name1",
"deviceId": "12121212121212"
};
// process the form
$.ajax({
type: 'POST',
crossDomain: true,
url: 'http://compay.ac-web-systems.eu/api/account/register',
data: formData, // our data object
dataType: 'json', // what type of data do we expect back from the server
encode: true
})
// using the done promise callback
.done(function (data) {
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
});
我非常确定 dataForm 数据结构或数据组装方式不正确。
我还需要一些建议,看看这是连接到 Web 服务的正确方法,还是有其他更好更快的 jQuery mobile 选项?
这里真的需要帮助。
提前致谢。
更新
我似乎无法访问这里的服务,这是真实的网址:http://yolp.ac-web-systems.eu/api/account/register
最佳答案
尝试删除
encode: true
您的数据对象已经是一个 json 对象。
关于javascript - 使用ajax调用注册用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25022798/