PHP表单提交 - 转换为jQuery的阿贾克斯表单、转换为、PHP、jQuery

由网友(人海孤独症)分享简介:有多容易下面的PHP表单提交转换为Ajaxy类型的形式。How easy is it to convert the following PHP form submission to an Ajaxy type form.下面是PHP:<?php //Send Tweetif(isset($_POST['submi...

有多容易下面的PHP表单提交转换为Ajaxy类型的形式。

How easy is it to convert the following PHP form submission to an Ajaxy type form.

下面是PHP:

<?php //Send Tweet
    if(isset($_POST['submit'])) {
    $qtweet = $_REQUEST['tweet'];
    $connection->post('statuses/update', array('status' => $qtweet));
    echo "<div style='padding-bottom: 5px; color: #0099FF;'>Updated your Timeline Successfully.</div>";
    }
?>

和HTML表单:

<form id="tweethis" method='post' action='index.php'>
    <textarea style="width: 346px;" name="tweet" rows="5" id="tweet" ></textarea>
    <br />
    <span id="charLeft">140</span>  Characters left
    <br />
    <input type='submit' value='Tweet This!' name='submit' id='submit' />
    <br />
</form>

我想使用Ajax所以页面犯规需要重新加载。

I'd like to use Ajax so the page doesnt need to reload.

推荐答案

pretty的方便。

Pretty easy.

使用$阿贾克斯,并检查了序列化()函数来转换表单数据。您还需要为prevent的默认行为和事件冒泡。该教程是pretty的好。

Use $.ajax, and check out the serialize() function to convert your form data. You will also need to prevent the default behaviour and event bubbling. This tutorial is pretty good.

在Ajax调用,你必须指定PHP页面,将处理请求。该脚本将处理表单提交,就像在普通的PHP的形式,然后呼应出任何输出。该输出将被传递回调用客户端

Inside the ajax call you have to specify the PHP page which will handle the request. That script will handle the form submission, like in normal PHP forms and then echoes out any output. That output will be passed back to the calling client.

阅读全文

相关推荐

最新文章