开发者

Get php file value

开发者 https://www.devze.com 2023-01-26 21:15 出处:网络
We have 5 inputs (type=\"text\") on html page /edit_person.php: <input id=\"name\" name=\"name\" value=\"\" />

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.ph开发者_JS百科p

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.


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);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号