javascript - 使用ajax调用注册用户

标签 javascript jquery ajax json jquery-mobile

我是 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/

相关文章:

javascript - 单击某个项目时出现错误查询切换打开所有 div?

javascript - 计算 fps 的函数

javascript - 在带有图像的某些 div 中水平滚动而不是垂直滚动?

jquery - 如何使用 Jquery Ajax MVC 下载 Excel 文件和 PDF 文件

javascript - 从 Firebase、angularJS 检索日期

Javascript window.getSelection() 替代方案

javascript - html onclick 打开的窗口在ajax 上不起作用

javascript - 服务器不可用

php - 向服务器发送答案,并从服务器返回相关数组以供下一个输入选项

javascript - 如何获取复选框提供的所有值