I try to load the document at the specified url after executing the script as follows: the script executes the url

mySite.loc/admin/menu/menuget/create

here is html

 <a href='#' id='#secures' data-formurl='/admin/menu/menuget'>Click</a> 

here is javascript

 $('#secures').click(function(e){ e.preventDefault; var path = $('#secures').data('formurl'); window.location.assign(window.location.hostname+path); } 

but for some reason I’m getting the following address mySite.loc/admin/menu/menuget/mySite.loc/admin/menu/menuget why not tell me?

  • ...ntDefault(); - Igor
  • @Igor do you think this is live code? Threw up from memory as an event to cancel. I’m generally sending the form and return false. Did I really complain about e.preventDefault? - Sergalas

1 answer 1

window.location.hostname returns you a domain without a protocol, and .assign() forms a relative path, substituting your current URL at the beginning.

And yet, instead of §('#sequre').data('formurl') it’s better to use §(e.currentTarget).data('formurl') , all of a sudden you have a double with the same id. Well, preventDefault is a function.

  • That is, you need to add a protocol? About id there will not be dubbing. - Sergalas