jQuery的更新一个div与PHP脚本 [英] jQuery update a Div with a PHP script

查看:115
本文介绍了jQuery的更新一个div与PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全不知道如何做到这一点,所以我只是要继续前进,并要求。

I have absolutely no idea how to do this, so I'm just gonna go ahead and ask.

我想要做的是一个PHP脚本我有一个外部文件,名为send.php更新一个div的内容。

What I want to do is update the contents of a div with a PHP script I have in an external file, called send.php.

所以我有这样一个div:

So I have a div like this:

<div class="classname">

</div>

和我想数据发布到这个send.php文件,然后更新该div与任何PHP脚本的结果是。可以这样做?

And I want to post data to this send.php file, and then update that div with whatever the outcome of the PHP script is. Can this be done?

推荐答案

对于简单的Ajax调用,我通常使用preFER的 $。加载作为其语法非常简洁。传递的参数作为一个对象(键/值对)将导致它使用POST请求:

For simple ajax calls, I normally prefer using $.load as its grammar is extremely concise. Passing parameters as an object (key/value pairs) will cause it to use a POST request:

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

如果你不需要它是一个POST,你可以添加参数作为查询字符串:

If you don't need it to be a POST, you can just add your parameters as a query string:

$('div.classname').load('send.php?param1=' + param1 + '&param2=' + param2);

这篇关于jQuery的更新一个div与PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆