未捕获TypeError:无法读取未定义窗口位置的属性'split'
问题描述:
我有这个错误,我谷歌关于它。但我没有发现我的问题未捕获TypeError:无法读取未定义窗口位置的属性'split'
var url = window.location.hash.split('?Token=')[1];
url = url.split('Token=');
function cambiarContrasena(usuario, completado, fallo) {
apiService.post('/api/usuario/cambiarContrasena?token='+url, usuario,
completado,
fallo);
}
我的价值不是空的或未定,任何人都可以帮我吗?谢谢!
答
使用href
而不是hash
。 hash
和href
之间
var url = window.location.href.split('?Token=')[1];
// url = url.split('Token='); no need to split it again.
function cambiarContrasena(usuario, completado, fallo) {
apiService.post('/api/usuario/cambiarContrasena?token='+url, usuario,
completado,
fallo);
}
区别是他们返回URL的不同部分。下面是URL的解剖:
在这种情况下window.location.hash
回报#00h02m30s
其中windows.location.href
回报整个URL。
答
我想应该是var url = window.location.split('?Token=')[1];
(不.hash
因为要拍摄参数)
+0
如果我不使用散列,我得到Uncaught TypeError:window.location.split不是函数 – Luis
+0
我的错误,应该是'.href',请参阅@Nobody的答案。 –
请出示的console.log的'值(window.location.hash);?' – 4castle
It's'#/ cambiarContrasena.html令牌= e12009cf-d48d-42e7-ba43-83b5082019bb' @ 4castle – Luis
你确定错误不在第二行 – adeneo