使用ajax调用注册用户
Posted
技术标签:
【中文标题】使用ajax调用注册用户【英文标题】:Register user by using ajax call 【发布时间】:2014-09-21 06:24:38 【问题描述】:我是 jQuery mobile 1.4.3 和 javascript 的新手,我正在尝试注册一个向网络服务发送 AJAX Post 调用的新用户,但我迷路了...
用户注册必须将以下 JSON 发送到 Web 服务:
"userName": "示例字符串 1",
"email": "示例字符串 2",
"密码": "示例字符串 3",
"confirmPassword": "示例字符串 4",
"name": "示例字符串 5",
"deviceId": "示例字符串 6"
网络服务网址: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 移动选项?
这里真的需要帮助。
提前致谢。
更新
我似乎无法访问这里的服务是真正的 url:http://yolp.ac-web-systems.eu/api/account/register
【问题讨论】:
您能访问您的网络服务网址吗?我不能... 你在使用 CORS 吗?如果不尝试使用 jsonp 代替。更多详情请见***.com/questions/3506208/jquery-ajax-cross-domain 更新了真实的网络服务 url 【参考方案1】:尝试删除
encode: true
您的数据对象已经是一个 json 对象。
【讨论】:
【参考方案2】:开启:http://jsfiddle.net/2a3tH/1/
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access.
这可能会对您有所帮助: "No 'Access-Control-Allow-Origin' header is present on the requested resource"
【讨论】:
我正在使用google POSTMAN测试api调用,但仍然没有成功以上是关于使用ajax调用注册用户的主要内容,如果未能解决你的问题,请参考以下文章