Joh*_*nny 4 php ajax jquery request
我完全不知道怎么做,所以我要继续问问.
我想要做的是使用我在外部文件中的PHP脚本更新div的内容,名为send.php.
所以我有这样的div:
<div class="classname">
</div>
Run Code Online (Sandbox Code Playgroud)
我想将数据发布到此send.php文件,然后使用PHP脚本的结果更新该div.可以这样做吗?
对于简单的ajax调用,我通常更喜欢使用$ .load,因为它的语法非常简洁.将参数作为对象(键/值对)传递将使其使用POST请求:
<a href="no-script.php" class="something">Click!</a>
$(document).ready(function() {
$('a.something').click(function(e) {
//prevent the href from being followed
e.preventDefault();
//inject div.classname with the output of send.php
$('div.classname').load('send.php', {param1: 'foo', param2: 'blah'});
});
});
Run Code Online (Sandbox Code Playgroud)
如果您不需要它作为POST,您只需将参数添加为查询字符串:
$('div.classname').load('send.php?param1=' + param1 + '¶m2=' + param2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11545 次 |
| 最近记录: |