Javascript Jquery Post没有';我不能参加形式课
在global.php中输入此php代码以生成表Javascript Jquery Post没有';我不能参加形式课,javascript,php,jquery,Javascript,Php,Jquery,在global.php中输入此php代码以生成表 <table> <tbody> <?php for($i=1; $i<=30; $i++) { echo ' <tr class="adding"> <td>'.$i.'</td> <td><input type="text" class="barcode" name="bar
<table>
<tbody>
<?php
for($i=1; $i<=30; $i++)
{
echo '
<tr class="adding">
<td>'.$i.'</td>
<td><input type="text" class="barcode" name="barcode[]" size="13" maxlength="13"></td>
<td><input type="text" class="prodotto" name="prodotto[]"></td>
<td><input type="text" class="prezzo" name="prezzo[]"></td>
</tr>';
}
?>
</tbody>
</table>
<script src="js/global.js"></script>
这是barcode_prodotto.php,我使用jquery post函数从数据库检索数据,如下所述:
<?php
mysql_connect("localhost","root","");
mysql_select_db('test');
if(isset( $_POST['name'])===true && empty($_POST['name'])===false){
$query=mysql_query("
SELECT prodotto as prodotto
FROM barcode_prodotto
WHERE barcode_prodotto='".mysql_real_escape_string(trim($_POST['name']))."'");
echo (mysql_num_rows($query)!==0)? mysql_result($query, 0, 'prodotto') : 'prodotto not found';
}
?>
将您的global js
更改为:在其他变量中获取当前对象,以便在post-ajax调用中使用,并找到td输入,将值放入其中
$(document).on("blur", ".barcode", function(){
var that=this;
var barcode =$(this).val();
// console.log(barcode);
if(barcode!='')
{
$.post('testing.php', {name: barcode}, function(data){
$(that).closest("tr").children('td').slice(2,3).find("input").val(data);
});
}
});
var barcode=$(this.find('input.barcode').val()代码>更改为var barcode=$(this.val()代码>它不会在ProDottopRelease字段中显示值,在chrome开发工具中发布ajax请求的屏幕截图已加载(global.php-200 OK-11.9459998715706MS-10.794KB)已加载(barcode_prodotto.php-200 OK-21.6470000139419MS-245B)已加载(barcode_prodotto.php-200 OK-12.49899998475124MS-245B)我可以使用图像,因为我的声誉很低
$(document).on("blur", ".barcode", function(){
var that=this;
var barcode =$(this).val();
// console.log(barcode);
if(barcode!='')
{
$.post('testing.php', {name: barcode}, function(data){
$(that).closest("tr").children('td').slice(2,3).find("input").val(data);
});
}
});