我有一个包含3个字段的搜索表单,其中一个是JQuery UI datepicker
和自定义wp_Query以显示搜索结果
和wordpress分页功能
搜索结果正确显示
但是,当我尝试转到下一页时,我认为它也会正确显示结果
,但网址看起来不正确
网址看起来像这样:
/page/2/?search=run&date#038;date
以及控制台中的以下错误:
jquery.js?ver=1.12.4:2 Uncaught Error: Syntax error, unrecognized expression: #038;date
at Function.fa.error (jquery.js?ver=1.12.4:2)
at fa.tokenize (jquery.js?ver=1.12.4:2)
at fa.select (jquery.js?ver=1.12.4:2)
at Function.fa (jquery.js?ver=1.12.4:2)
at Function.a.find (jquery-migrate.min.js?ver=1.4.1:2)
at n.fn.init.find (jquery.js?ver=1.12.4:2)
at n.fn.init.a.fn.find (jquery-migrate.min.js?ver=1.4.1:2)
at a.fn.init.n.fn.init (jquery.js?ver=1.12.4:2)
at new a.fn.init (jquery-migrate.min.js?ver=1.4.1:2)
at n (jquery.js?ver=1.12.4:2)
当我从表单中删除日期字段时,它就可以正常工作。
这是与日期有关的JQuery部分
jQuery(function() {
jQuery( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat:'m-yy',
onClose: function(dateText, inst){
jQuery(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth,1));
var selected_month = inst.selectedMonth+1;
var month = jQuery("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = jQuery("#ui-datepicker-div .ui-datepicker-year :selected").val();
var full_date = jQuery(".datepicker").datepicker("getDate");
var myElement = document.getElementById("datepicker");
console.log(myElement);
}
});
});
有什么主意我该如何从网址中删除“#038; date”部分?
我希望用户进入搜索结果的第二页时,网址看起来像这样
/ page / 2 /?search =运行&日期
代替这个
/ page / 2 /?search = run&date#038; date
似乎此问题与日期选择器无关 我仍然不知道为什么以及如何解决它,但是这个问题不能正确描述问题
答案 0 :(得分:0)
Here, I am sharing about syntax for How to remove "#038;date" part from the url
alert(url.substring(0, url.indexOf('?')));
Also, Here is a basic workaround for you:
//the URL ( decode it just for GOOD practice)
var someRandomUrl = decodeURI("http://example.com?modal=name");
//here we do the splitting
var splittedParts = someRandomUrl.split("?");
// the first part of the array will be URL you will require
var theURL = splittedParts[0];
// the second part of the array will be the Query String
var theQuery = splittedParts[1];
alert(theURL);
I hope that this is useful for you.