calling function in window addEventListener popstate, not working
-
23-06-2021 - |
سؤال
The problem i am facing is in the GetAjaxPageBack function whenever i try to write any function in it, like split, or any other function it do nothing and if i commented out the line var url = url.split("?"); is start working fine, but why i need to split the url and want to get the query string and want to resend it using ajax to fetch the records.
<script language="javascript">
function GetAjaxPageBack(url) {
//this line is not working
var url = url.split("/");
alert(url);
/* $.post(url,
function(data){
if (data != "")
{
}
});
*/}
function GetAjaxPage(value)
{
if(value=='n')
{
val = $('#abc').val()+1;
$('#abc').val(val);
}else
{
val = $('#abc').val()-1;
$('#abc').val(val);
}
history.pushState(null, null, "?abc="+$('#abc').val());
window.addEventListener("popstate", function(e) {
GetAjaxPageBack(location);
});
}
</script>
</head>
<body><br />
<a href="javascript:;" onclick="GetAjaxPage('p')">Prev</a> |
<a href="javascript:;" onclick="GetAjaxPage('n')">Next</a>
<br /><br />
<input type="text" name="abc" id="abc" value="1" >
please help out, thanks
المحلول
The location isn't a string but a Location object. Try using it's native functions or converting it to a string first.
location.toString().split('/')
لا تنتمي إلى StackOverflow