PHP表单提交 - 转换为jQuery的阿贾克斯 [英] PHP form submit - converting to jQuery .Ajax

查看:130
本文介绍了PHP表单提交 - 转换为jQuery的阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有多容易下面的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的默认行为和事件冒泡。该<一href="http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/"相对=nofollow>教程是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.

这篇关于PHP表单提交 - 转换为jQuery的阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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