Javascript 使用jquery和ajax连接到Rest服务器
我正在尝试使用jquery/ajax调用rest服务器 rest服务器内置于Codeigniter中 ajax功能如下所示:Javascript 使用jquery和ajax连接到Rest服务器,javascript,jquery,rest,Javascript,Jquery,Rest,我正在尝试使用jquery/ajax调用rest服务器 rest服务器内置于Codeigniter中 ajax功能如下所示: var req = $.ajax({ type: 'GET', url: "http://localhost/projects/comp6300Server/index.php/resources/token//username/" + email + "/password/" + pword + "/institution/" + inst, c
var req = $.ajax({
type: 'GET',
url: "http://localhost/projects/comp6300Server/index.php/resources/token//username/" + email + "/password/" + pword + "/institution/" + inst,
contentType: "application/json; charset=utf-8",
dataType: "json"
})
http://localhost/projects/comp6300Server/index.php/resources/token//username/etambie@yahoo.com/password/qwerty/institution/BCC
生成的请求如下所示:
var req = $.ajax({
type: 'GET',
url: "http://localhost/projects/comp6300Server/index.php/resources/token//username/" + email + "/password/" + pword + "/institution/" + inst,
contentType: "application/json; charset=utf-8",
dataType: "json"
})
http://localhost/projects/comp6300Server/index.php/resources/token//username/etambie@yahoo.com/password/qwerty/institution/BCC
返回的状态为“400错误请求”
我认为问题可能在于传入的电子邮件。”etambie@yahoo.com". 有没有办法让ajax自动将“@”转换为“%40”,或者我必须手动转换字符串中的所有特殊字符?有两件事需要检查:
因为
cache=false
。这会向字符串添加一个随机时间戳,以确保它不会被缓存。谢谢,这会清除这部分内容。我只需要找出实际分号inst;,有什么问题变量inst
之后的code>可能会导致此错误,您可能只是尝试了一下,添加分号会使jquery无效。语法如下:url:“myurl”,。含义是删除它,因为上面显示的字符串包含分号。。。不管怎样,你的路线是什么样的?我假设这类似于CodeIgnitertoken_get是我调用的rest服务的名称。然后是参数。我试着去掉第二个,但还是有400个错误