【发布时间】:2018-03-21 17:47:00
【问题描述】:
我有一个使用 getJSON 的 JQuery 函数来带来一些 userifo。是这样的:
$.getJSON("http://server.com/?apirequested=userinfo", function(data){
...
...
});
这很好用,但我正在尝试将其更改为使用亲戚网址的多个服务器使用相同的代码。
我正在尝试几件事,例如:
$.getJSON($(location).attr('hostname')+"/?apirequested=userinfo" ...
或
$.getJSON($(location).attr('protocol')+$(location).attr('hostname')+"/?apirequested=userinfo",
或
$.getJSON(location.hostame+"/?apirequested=userinfo" ...
但它不起作用。我做错了什么?
有什么建议吗?
提前感谢您的宝贵时间。
【问题讨论】:
-
你读过
location的任何文档吗? -
…可分别通过 Document.location 和 Window.location 访问…。顺便说一句,
location接口与jQuery无关。 -
为什么
$.getJSON(location.host+"/?apirequested=userinfo"不起作用?
标签: javascript jquery getjson hostname