这是我用于按钮的代码。出现,并且该按钮是可单击的。
foreach ($result as $pers) {
echo ('<form>');
echo ('<h3>Naam</h3>');'<br>';
echo "<input type='submit' name='nameupdate' value='$pers->name' data-href='?persUp=".$pers->username."&persDa=".$pers->name."'>";
echo ('</form>');
}
当我单击按钮时,应创建此表单,但它不会出现。也没有出现回声dabdab。
if(isset($_POST['nameupdate']))
{
echo('dabdab');
if(isset($_GET['persDa']))
{
$did = $_GET['persDa'];
echo "<input type='text' name='nmbox' value='$did'>";
echo "<input type='submit' name='nmupdate' value='Update'>";
}
}
我在做什么错?请让我知道。
JavaScript
$(document).ready(function() {
//Function for preview image.
$(function() {
$(":file").change(function() {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#message').css("display", "none");
$('#preview').css("display", "block");
$('#previewimg').attr('src', e.target.result);
};
//Function for deleting preview image.
$("#deleteimg").click(function() {
$('#preview').css("display", "none");
$('#file').val("");
});
//Function for displaying details of uploaded image.
$("#submit").click(function() {
$('#preview').css("display", "none");
$('#message').css("display", "block");
});
});
并在头部:
<link rel="stylesheet" href="themes/themerollertest.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
答案 0 :(得分:0)
也许是太多()并且错误使用PHP是这种情况的理由?
您的代码:
foreach ($result as $pers) {
echo ('<form>');
echo ('<h3>Naam</h3>');'<br>';
echo "<input type='submit' name='nameupdate' value='$pers->name' data-href='?persUp=".$pers->username."&persDa=".$pers->name."'>";
echo ('</form>');
}
应该是:
foreach ($result as $pers) {
echo '<form>';
echo '<h3>Naam</h3><br>';
echo '<input type="submit" name="nameupdate" value="'.$pers->name.'" data-href="?persUp='.$pers->username.'&persDa='.$pers->name.'">';
echo '</form>';
}
编辑:尝试
表格:
foreach ($result as $pers) {
echo '<form action="" method="POST">';
echo '<h3>Naam</h3><br>';
echo '<input type="hidden" name="persUp" value="'.$pers->username.'">';
echo '<input type="hidden" name="persDa" value="'.$pers->name.'">';
echo '<input type="submit" name="nameupdate">';
echo '</form>';
}
和POST:
if(isset($_POST['nameupdate']))
{
echo('dabdab');
if(isset($_POST['persDa']))
{
$did = $_POST['persDa'];
echo "<input type='text' name='nmbox' value='".$did."'>";
echo "<input type='submit' name='nmupdate' value='Update'>";
}
}
答案 1 :(得分:0)
正如我所见,您应该使用ajax一次发送一次POST
和GET
,为此,我建议您将此拍子分开到新文件中
if(isset($_POST['nameupdate']))
{
echo('dabdab');
if(isset($_GET['persDa']))
{
$did = $_GET['persDa'];
echo "<input type='text' name='nmbox' value='$did'>";
echo "<input type='submit' name='nmupdate' value='Update'>";
}
}
在具有视图的主文件中,应添加这样的ajax
$("input[name='nameupdate']").on('click', function(e){
e.preventDefault();
var url = $(this).data('href'),
nameupdate = $(this).val();
$.ajax({
type: "POST",
url: url,
data: {
nameupdate: nameupdate,
},
success: function (response) {
// here you should choose place where to put your result
$('#result').html(response)
}
});
});
编辑:或者像这样简单地更改代码
foreach ($result as $pers) {
echo '<form action="?persUp='.$pers->username.'&persDa='.$pers->name.'" method="POST">';
echo '<h3>Naam</h3><br>';
echo "<input type='submit' name='nameupdate' value=".$pers->name." data-href=''>";
echo '</form>';
}