代码已更新
如果值在成功时从ajax传递到textbox,那么如何将该值与MySQL where子句一起使用?
Ajax代码:
var recstr1 = "Ramesh Kumar";
data={txtname:recstr1};
$.ajax({
type: 'POST',
url: 'getprojectnamerep.php',
data: data,
datatype: "html",
success: function(data){
console.log(data);
$("#txtname").html(data);
},
error: function(data){ alert("Something went wrong !"); }
});Mysql查询:
<?php $name = $_POST['txtname'];
select * from customer where custname = '$name';当我运行这段代码并检查Chrome浏览器中的"Elements“时,它显示的值如下:
<input type="text" id="txtname" class="form-control" readonly="" name="txtname">Ramesh Kumar</input>而它应该如下所示:
<input type="text" id="txtname" class="form-control" readonly="" name="txtname" value="Ramesh Kumar">由于值没有传入value='‘,这就是var_dump()返回空的原因。
我哪里错了,请指导和帮助?
getprojectnamerep.php
<?php session_start(); ?>
<?php
$rpname = $_POST['txtname'];
echo $rpname;
?>发布于 2018-03-06 15:17:34
$('#txtname').html('something'); // this will put "something" in innerHTML
$('#txtname').val('something'); // this will set the VALUE attribute
// of the input to "something"https://stackoverflow.com/questions/49125194
复制相似问题