有问题任何人有任何想法?我只发布是代码所必需的。我基本上有一个HTML表单,我希望从表单中的字段获取值,然后再提交ajax调用并填充另一个字段。我认为如果我能够将该表单中输入的Txt转换为modcreate.php中的PHP变量,它将起作用。因为如果我手动输入没有变量的细节的话。如何通过AJAX调用将表单值传递给PHP变量?
mainpage.php
从形式<tr>
<th>Service Tag:</th>
<th><input type="text" id="inputTag" name="inputTag" value="" onblur="this.value=this.value.toUpperCase()"></td>
</tr>
和
<tr>
<th>Model:</th>
<th>
<input type="text" id="inputModel" name="inputModel" value="">
<a href="#" id="updateBtn">Populate</a>
<div id="spinner">
<img src="\images\ajax-load.gif" alt="Loading..."/>
</div>
</th>
</tr>
<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: "modcreate.php",
data: { 'txt1': $('#inputTag').val() },
success: function(data) {
}
});
});
</script>
modcreate.php
<?php
$field1value = $_GET['txt1'];
$file_string = file_get_contents('blahblah.com/'.$field1value);
preg_match("/<title>Product Support for (.+)\| Dell/i", $file_string, $matches);
$print = "$matches[1]";
echo $print;
?>
******解
相关部分*** *** 我的aja X呼叫缺少它发送的数据回表单字段
这里的部分是工作AJAX是什么样子,现在感谢你们所有的指针
<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: "modcreate.php",
data: { 'txt1': $('#inputTag').val() },
success: function(data) {
$('#inputModel').val(data); //this was the missing part
}
});
});
</script>
是否modcreate.php给你任何结果,如果你直接去它? (例如:导航到modcreate.php?txt1 = somethinghere – Joao
你必须定义你的AJAX方法'type:“POST”'或'type:“GET”' –
@AdamZapp - jQuery默认为'GET' - 设置它 – 2013-10-14 21:00:11