douche3791 2010-11-22 12:07
浏览 38
已采纳

获取php文件值

We have 5 inputs (type="text") on html page /edit_person.php:

<input id="name" name="name" value="" />
<input id="surname" name="surname" value="" />
<input id="age" name="age" value="" />
<input id="begin" name="begin" value="" />
<input id="end" name="end" value="" />

And a php file /scripts/db.php

If we open in browser /scripts/db.php?get=1 it will give something like (an array with values):

$data = Array(
[name]=>Mark,
[surname]=>Twain,
[age]=>74,
[begin]=>November 30, 1835,
[end]=>April 21, 1910
)

How can we request /scripts/db.php?get=1 by ajax on /edit_person.php and insert received data to the inputs?

jQuery last version is used and PHP 5.2.

If input currently has some value, it should be replaced.

Output format of db.php can be changed, you can request options which would be better.

Thanks.

  • 写回答

1条回答 默认 最新

  • doufen3786 2010-11-22 12:09
    关注

    db.php seems to be outputting the array in some custom, PHP-like format. I wouldn't do that. Use json_encode() instead: jQuery's Ajax can handle JSON data natively.

    • Docs on jQuery.getJSON() with examples

    • If your JSON data is in a variable named data, the insertion into each input will be a simple $("#name").val(data.name);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)