假设此示例HTML:
<input type="text" name="email" id="email" /><input type="text" name="first_name" id="first_name" /><input type="text" name="last_name" id="last_name" />
您可以使用以下javascript:
$("#email").bind("change", function(e){ $.getJSON("http://yourwebsite.com/lokup.php?email=" + $("#email").val(), function(data){ $.each(data, function(i,item){ if (item.field == "first_name") { $("#first_name").val(item.value); } else if (item.field == "last_name") { $("#last_name").val(item.value); } }); });});
然后,您只有一个PHP脚本(在本例中为lookup.php),该脚本在查询字符串中包含一封电子邮件,并返回一个JSON格式的数组以及您要访问的值。这是实际访问数据库以查找值的部分:
<?php//look up the record based on email and get the firstname and lastname...//build the JSON array for return$json = array(array('field' => 'first_name', 'value' => $firstName), array('field' => 'last_name', 'value' => $last_name));echo json_enpre($json );?>
您需要做其他事情,例如清理电子邮件输入等,但是应该使您朝着正确的方向前进。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)