Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery和ajax连接到Rest服务器_Javascript_Jquery_Rest - Fatal编程技术网

Javascript 使用jquery和ajax连接到Rest服务器

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

我正在尝试使用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,
    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”,或者我必须手动转换字符串中的所有特殊字符?

有两件事需要检查:

  • 可能会在每个请求都是唯一的基础上添加“\u1”参数。如果不这样做,那么浏览器可能会尝试从其缓存中获取调用URL的结果,这可能不是您想要的结果
  • 在错误的要求下。。。您确定要在url中的“令牌”一词后加两个斜杠吗

  • 因为
    cache=false
    。这会向字符串添加一个随机时间戳,以确保它不会被缓存。谢谢,这会清除这部分内容。我只需要找出实际分号
    inst;,有什么问题inst
    之后的code>可能会导致此错误,您可能只是尝试了一下,添加分号会使jquery无效。语法如下:url:“myurl”,。含义是删除它,因为上面显示的字符串包含分号。。。不管怎样,你的路线是什么样的?我假设这类似于CodeIgnitertoken_get是我调用的rest服务的名称。然后是参数。我试着去掉第二个,但还是有400个错误