Javascript 用于填充表单字段jquery的AJAX PHP变量
试图找到一个解决方案任何帮助或指点,使我在正确的方向将不胜感激 场景:我有一个HTML表单,用于使用PHP修改mysql数据库。我想当页面加载时,它在表单上有一个字段,从数据库中提取,这很容易使用Javascript 用于填充表单字段jquery的AJAX PHP变量,javascript,php,jquery,ajax,forms,Javascript,Php,Jquery,Ajax,Forms,试图找到一个解决方案任何帮助或指点,使我在正确的方向将不胜感激 场景:我有一个HTML表单,用于使用PHP修改mysql数据库。我想当页面加载时,它在表单上有一个字段,从数据库中提取,这很容易使用 <input type="text" name="inputTag" value="<?php echo $people['Service Tag']; ?>" onblur="this.value=this.value.toUpperCase()" /> 谢谢你,感
<input type="text" name="inputTag" value="<?php echo $people['Service Tag']; ?>" onblur="this.value=this.value.toUpperCase()" />
谢谢你,感觉你把我带到了正确的方向。然而,我仍然有问题。如果我只是调用php文件,它会打印出所需的值,但是单击“更新字段”链接除了将#添加到URL的末尾外,什么都不做。通过进一步的修改,我通过稍微修改使其工作,谢谢code
$.ajax({url:“test.php”,success:function(data){//使用接收到的数据设置输入字段的值$('#serviceTag').val(data);code
<?php
$file_string = file_get_contents('http://blahblah.com/');
preg_match("/<title>Product Support for (.+)\| HP/i", $file_string, $matches);
$print = "$matches[1]";
?>
<script type="text/javascript" src="\js\jquery-latest.js"></script>
<script type="text/javascript">
function populatetag() {
$.get("\portable\test.php");
return false;
}
</script>
<script type="text/javascript" src="\js\jquery-latest.js"></script>
<script type="text/javascript">
$('#updateBtn').click(function(e){
//to disable the click from going to next page
e.preventDefault();
$.ajax({
url: "test.php",
success: function(data){
//set the value of your input field with the data received
$('#model').val(data);
}
}
);
});
</script>
<input type="text" id="serviceTag" name="inputTag" value="<?php echo $people['Service Tag']; ?>"/>
<a href="#" id="updateBtn">Update Field</a>
<script>
$('#updateBtn').click(function(e){
//to disable the click from going to next page
e.preventDefault();
$.ajax(
'your-php-script.php', function(data){
//set the value of your input field with the data received
$('#serviceTag').val(data);
}
);
});
</script>