gpt4 book ai didi

javascript - 单击按钮时填充 javascript 变量

转载 作者:行者123 更新时间:2023-12-02 14:41:11 25 4
gpt4 key购买 nike

为了与 api 结合构建分页,当我按下 next 按钮时,我希望将值 next 分配给 JavaScript 变量,以便可以发送它到 PHP 脚本。到目前为止我已经有了这个,但我对 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(排序){ var ajax请求;//Ajax 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;
}
}
}

如何才能使 Javascript 变量 (nextpage) 保持为空,直到按钮(name="nextpage" with value="nextpage") 被按下?当按下时,JavaScript 变量 nextpage 应包含“nextpage”

最佳答案

发布变量而不是使用 GET:

document.getElementById('nextpage').onclick = function(e){

ajaxRequest.open("POST", link, true);
if (nextpage) ajaxRequest.send("nextpage=yes");
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;
}
}
}

关于javascript - 单击按钮时填充 javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36992770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com