douyou7878 2012-10-08 15:36
浏览 46

使用Zip通过jQuery AJAX预填充城市/州表格

I'm running into a problem that I can solve fine by just submitting a form and calling a db to retrieve/echo the information, but AJAX seems to be a bit different for doing this (and is what I need). Earlier in a form process I ask for the zip code like so:

<input type="text" maxlength="5" size="5" id="zip" />

Then I have a button to continue, but this button just runs a javascript function that shows the rest of the form. When the rest of the form shows, I want to pre-populate the City input with their city, and pre-populate the State dropdown with their state. I figured I would have to find a way to set city/state to variables, and echo the variables into the form. But I can't figure out how to get/set those variables with AJAX as opposed to a form submit. Here's how I did it without ajax:

$zip = mysql_real_escape_string($_POST['zip']);
$q = " SELECT city FROM citystatezip WHERE zip = $zip"; 
$r = mysql_query($q); 
$row = mysql_fetch_assoc($r); 
$city = $row['city'];

Can anybody help me out with using AJAX to set these variables? Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作