2017-04-03 30 views
1

我有这个错误,我谷歌关于它。但我没有发现我的问题未捕获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); 
     } 

我的价值不是空的或未定,任何人都可以帮我吗?谢谢!

+0

请出示的console.log的'值(window.location.hash);?' – 4castle

+0

It's'#/ cambiarContrasena.html令牌= e12009cf-d48d-42e7-ba43-83b5082019bb' @ 4castle – Luis

+0

你确定错误不在第二行 – adeneo

回答

1

使用href而不是hashhashhref之间

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的解剖:

Anatomy of a URL

在这种情况下window.location.hash回报#00h02m30s其中windows.location.href回报整个URL。

+0

相同问题未捕获TypeError:无法读取undefined的属性'split' – Luis

+0

向我们显示console.log(location.href) –

+0

http:// localhost:55718/Cliente /并且应该是http:// localhost:55718/Cliente /# /login.html – Luis

0

我想应该是var url = window.location.split('?Token=')[1];(不.hash因为要拍摄参数)

+0

如果我不使用散列,我得到Uncaught TypeError:window.location.split不是函数 – Luis

+0

我的错误,应该是'.href',请参阅@Nobody的答案。 –

相关问题