[英]Jquery and php not pass data between two pages
I have two pages in php and I need that the value of radioButton selection pass to another page, but it not work. 我在php中有两个页面,我需要将radioButton选择的值传递给另一个页面,但它不起作用。 The jquery code of the page that send the data is:
发送数据的页面的jquery代码是:
$(document).ready(function(){
$("#continue").click(function(){
var val = $("input[@name='opt']:checked").val();
$.ajax({
type: 'GET',
url:'editor.php',
data:'radio=' + val,
dataTyoe:'html',
succes: alert(val)
});
});
});
The html code into the php page is: 进入php页面的html代码是:
<input type="radio" id="opt" name="opt" value="opt1" checked="checked">Opt 1<br/>
<input type="radio" id="opt" name="opt" value="opt2"/>opt2<br />
<input type="radio" id="opt" name="opt" value="opt3"/>opt3<br />
<a href="editor.php" id="continue">Guardar continuar</a><br/>
And the code of the page that recive data is the follow. 并且返回数据的页面的代码如下。
<?php
$valor = $_REQUEST['radio'];
echo $valor
?> ?>
Thanks 谢谢
There were some spelling mistakes and need some correction. 有一些拼写错误,需要一些纠正。 Try the following code;
请尝试以下代码;
$(document).ready(function(){
$("#continue").click(function(){
var val1 = $("input[name='opt']:checked").val();
$.ajax({
type: 'GET',
url:'editor.php',
data:'radio=' + val1,
success: function(){
alert(val1);
}
});
});
});
你拼错了成功:它应该是成功的:
You may have some errors : try replacing dataTyoe:'html'
for dataType:'html'
, Also $("input[@name='opt']:checked")
by $("input[@name=opt]:checked")
... and the success callback too... 您可能会
dataTyoe:'html'
一些错误:尝试将dataTyoe:'html'
替换为dataType:'html'
,同时$("input[@name='opt']:checked")
by $("input[@name=opt]:checked")
......以及成功的回调......
It would look like : 它看起来像:
var val = $("input[@name=opt]:checked").val();
$.ajax({
type: "GET",
url: "editor.php",
data:'radio='+val,
dataType: "html",
async:false,
success: function(){
alert(val);
}
}
);
Also you could remove the link from the html : 你也可以从html中删除链接:
<a href="#" id="continue">Guardar continuar</a><br/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.