Javascript js";脚本“;XMLHttpRequest调用前的文件夹名称
我在Web服务器的“scripts”文件夹中有一个名为myscripts.js的javascript文件。可通过以下方式访问: 在myscripts.js中有一个javascript函数,它对我的网站的somemethod.html进行XMLHttpRequest调用。以下是呼叫代码:Javascript js";脚本“;XMLHttpRequest调用前的文件夹名称,javascript,jquery,Javascript,Jquery,我在Web服务器的“scripts”文件夹中有一个名为myscripts.js的javascript文件。可通过以下方式访问: 在myscripts.js中有一个javascript函数,它对我的网站的somemethod.html进行XMLHttpRequest调用。以下是呼叫代码: xmlhttp.open("GET","somemethod.html",false); 99%的时间一切正常。但我发现一些浏览器在调用前添加了“脚本/”。结果是这样一个调用: http://www.exam
xmlhttp.open("GET","somemethod.html",false);
99%的时间一切正常。但我发现一些浏览器在调用前添加了“脚本/”。结果是这样一个调用:
http://www.example.com/scripts/somemethod.html
什么时候应该是这样:
http://www.example.com/somemethod.html
这是一个定制的Web服务器(即,我基本上处理所有请求)
http://www.example.com/scripts/somemethod.html
open(“GET”,“”,false)…然后使用该脚本文件中的代码执行XHR调用,调用将在功能正常的浏览器上相对于
index.html
,而不是script.js
。我从不使用相对请求,我构建了自己的url,通过js代码构建url,并使用“toString”方法传递url,以准确地给出我需要的url
另外,尽量不要再使用同步XHR调用,理想情况下应该使用异步和回调,这很痛苦,但这是最好的
client . open(method, url [, async = true [, username = null [, password = null]]])
Sets the request method, request URL, and synchronous flag.
Throws a "SyntaxError" exception if either method is not a valid HTTP method or url cannot be parsed.
Throws a "SecurityError" exception if method is a case-insensitive match for `CONNECT`, `TRACE` or `TRACK`.
Throws an "InvalidAccessError" exception if async is false, the JavaScript global environment is a document environment, and either the timeout attribute is not zero, the withCredentials attribute is true, or the responseType attribute is not the empty string.
来源:“一些浏览器”-什么浏览器?你确定他们是浏览器而不是垃圾机器人吗?很好。我将把用户代理添加到我的日志中。正如@Quentin所说的,可能是某种爬虫。我将记录用户代理/ip地址以了解更多信息。