将js变量传递到外部php页面



我有一个文件main.js,其中每个步骤都将选定的变量传递到php页面,我需要将一些变量传递到另一个php页面。

这是main.js的一段代码,我试图获得'optionsContent'变量,并将其放在一个index.php页面中的'div id="rip"with'document.getElementById("rip(.innerHTML=optionsContent;'但尝试在new.php页面中使用"href"传递此变量,但无法使用

if( selectedOptions.length == 0 ) {
optionsContent = '<li><p style="color:#FF0000">Nessuna Riparazione Selezionata</p></li>';
} else {
selectedOptions.each(function(){
optionsContent +='<li><p>RIPARAZIONE '+$(this).find('.searchText1').text()+'</p>'+' - '+'<p style="color:#0012ff">' +$(this).find('.price').text()+'</p></li>';
//optionsContent +='<li><p>'+$(this).find('p').text()+'</p></li>';
//document.getElementById("new").innerHTML = optionsContent;
document.getElementById("rip").innerHTML = optionsContent;


});
}
self.summary.find('.summary-accessories').children('li').remove().end().append($(optionsContent));
}
}); 

index.php页面


<div id="rip">** HERE GET 'optionsContent' VAR CORRECTLY **</div>
<li class="next nav-item">
<ul>
<li class="visible"><a href="#0">Modello</a></li>
<li><a href="#0">Colore</a></li>
<li><a href="#0">Riparazione</a></li>
<li><a href="#0">Sommario</a></li>
<li class="buy"><a href="/new.php?riparation=<? $rip; ?>">Prenota</a></li>
</ul>
</li>

在新的php页面中

<?php
$riparation = $_GET['riparation'];
?>
<input name="riparation"><?php echo $riparation; ?></input>

但不起作用

有什么帮助吗?

您可以使用cookie或数据存储API在页面之间保存数据。

index.html:

<?php
// set the cookies:
setcookie("riparation", "myDataFromApp");
// Render the page:
echo "<h1>This works!</h1>"
?>

另一个页面(需要jQuery cookie插件(:

var riparation = $.cookie("riparation"); // riparation = "myDataFromApp"

最新更新