对于与api结合的构建分页,当我按下下一个按钮时,我希望将值next
分配给一个javascript变量,以便它可以发送到PHP脚本。我有这到目前为止,但我不是很熟悉JavaScript:当点击按钮时填充javascript变量
nextpage = document.getElementById('nextpage').onclick = document.getElementById('nextpage').value;
if(!nextpage==0){
link =link+"&nextpage="+nextpage;
}
这样的JavaScript变量被发布到URL等等,另一方面PHP脚本可以把它捡起来像这样。对于其他变量使用:
mantinee = document.zoekform.mantinee.value;
if(!mantinee==0){
link =link+"&mantinee="+mantinee;
}
如果我这样做,那么它直接发布到URL,这样的PHP脚本总是认为它需要跳到下一个页面是不是我的本意。点击时,其侧面的按钮将调用ajaxgetinfo()
。
query.php
if(isset($_POST['nextpage']))
{
$nextpage = $_POST['nextpage'];
}
这里是所有得到每个变量并将它们传送的JavaScript。这是那里的下一页也需要运行
function vorige(){
sort = 'vorige';
ajaxGetInfo(sort);
}
功能ajaxGetInfo(排序) { 变种ajaxRequest; //德可变笏阿贾克斯mogelijk maakt
try{
// Chrome, Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
link="query.php?";
datumreeks='';
if(document.zoekform.zo.checked==true){datumreeks="zondag";}
if(document.zoekform.ma.checked==true){datumreeks=datumreeks+"maandag-";}
if(document.zoekform.di.checked==true){datumreeks=datumreeks+"dinsdag-";}
if(document.zoekform.wo.checked==true){datumreeks=datumreeks+"woensdag-";}
if(document.zoekform.don.checked==true){datumreeks=datumreeks+"donderdag-";}
if(document.zoekform.vr.checked==true){datumreeks=datumreeks+"vrijdag-";}
if(document.zoekform.za.checked==true){datumreeks=datumreeks+"zaterdag-";}
link = link+"&datumreeks="+datumreeks;
datepicker = document.zoekform.datepicker.value;
if(!datepicker==0){link =link+"&datepicker="+datepicker;}
datepicker2 = document.zoekform.datepicker2.value;
if(!datepicker2==0){link =link+"&datepicker2="+datepicker2;}
zaal = document.zoekform.zaal.value;
if(!zaal==0){link =link+"&zaal="+zaal;}
genre = document.zoekform.genre.value;
if(!genre==0){link =link+"&genre="+genre;}
profiel = document.zoekform.profiel.value;
if(!profiel==0){link =link+"&profiel="+profiel;}
internationaal = document.zoekform.internationaal.value;
if(!internationaal==0){link =link+"&internationaal="+internationaal;}
prijslaag = document.zoekform.prijslaag.value;
if(!prijslaag==0){link =link+"&prijslaag="+prijslaag;}
prijshoog = document.zoekform.prijshoog.value;
if(!prijshoog==0){link =link+"&prijshoog="+prijshoog;}
mantinee = document.zoekform.mantinee.value;
if(!mantinee==0){link =link+"&mantinee="+mantinee;}
document.getElementById('nextpage').onclick = function(e){
ajaxRequest.open("POST", link, true);
if (nextpage) ajaxRequest.send("nextpage=yes");
}
ajaxRequest.open("GET", link, true);
ajaxRequest.send(null);
document.getElementById("info").innerHTML = '<div align=center><i class="material-icons w3-spin w3-jumbo">refresh</i></br>Blijft dit staan? <a href="" onclick="ajaxGetInfo()">Klik hier.</a></div>';
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById("info").innerHTML = ajaxRequest.responseText;
}
}
}
我怎样才能让这个直到按钮(name="nextpage"
与value="nextpage"
)按下JavaScript变量(nextpage
)仍然是空的?当按下时,JavaScript变量nextpage
应该包含“下一页”
但不会有任何按钮,点击?并提交刷新页面。我用选项卡建立网站,所以刷新不是一个选项 – Mark
也应该只填充nextpage的值时按其他明智需要有一个不同的值,这将是随机的,因为如果该值为空脚本将不会运行 – Mark
你在你的问题中说过会有'下一个'按钮?自您编辑问题后,我不理解您的问题。 – markt