0
當ID號輸入到ID文本框中時,我的腳本應該在文本框中調出數據。問題是,與身份證號碼有關的信息出現了,但只有當我輸入身份證號碼並重新加載頁面,而不是輸入值時,其他信息纔會自動出現。Ajax PHP代碼不起作用
這裏是腳本
<script language="javascript" type="text/javascript">
jQuery(document).ready(function()
{
$("#tid").keyup(function()
{
var value = $(this).val();
$.ajax({
url: "index.php",
type: 'POST',
data: {itemNo: $("#tid").val() },
success: function(data)
{
var obj = jQuery.parseJSON(data);
$("#tname").val(obj.name);
$("#tprice").val(obj.price);
}
});
});
});
</script>
<?php
$client = new nusoap_client("http://localhost:1234/cwork/webfunction.php#");
$ans = $client->call('ArraySearch', array("inum" => $stf));
echo "<br>";
$vars = explode(",", $ans);
?>
<label> Item# : </label> <input type="text" class="tid" name="txtid" value="<?php if (count($vars) > 1) echo htmlspecialchars($stf); ?> " /> <br> <br>
<label> Name :</label> <input type="text" name="txtname" class="tname" size="25" value="<?php if (count($vars) > 1) echo htmlspecialchars($vars[1]); ?>" /> <br> <br>
<label> Price :</label> <input type="text" name="txtprice" class="tprice" value="<?php if (count($vars) > 1) echo htmlspecialchars($vars[2]); ?>" /><br> <br>
<label> Quantity:</label> <input type="text" name="txtqty" /> <br> <br>
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" class = "submit" value="Add to cart" onclick="myfnc()"/>
感謝你們的信息,但我仍然需要手工重新加載頁面的數據來在文本框 – Shasha 2014-11-02 19:32:58
使用***。text()***而不是***。val()*** – JMc 2014-11-02 20:16:03
JMc謝謝,但仍然不能解決問題 – Shasha 2014-11-02 21:03:09