我的ajaxForm重定向到PHP脚本 [英] My ajaxForm redirects to a PHP script

查看:72
本文介绍了我的ajaxForm重定向到PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提交表单时,ajax始终重定向到some.php,如何防止提交表单后重定向到PHP脚本,我希望页面重定向到index.html

When I submit my form ajax always redirects to some.php, how can I prevent this from redirecting to the PHP script instead after submitting the form I want the page redirects to the index.html

<html>
<head>
<meta charset="utf-8">
<title>jQuery Adapter &mdash; CKEditor Sample</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script src="../ckeditor.js"></script>
<script src="../adapters/jquery.js"></script>
<script src="jquery.form.js"></script>

<script>
    CKEDITOR.disableAutoInline = true;

    $( document ).ready( function() {
        $( '#editor1' ).ckeditor(); // Use CKEDITOR.replace() if element is <textarea>.
        $( '#editable' ).ckeditor(); // Use CKEDITOR.inline().
    } );

    function setValue() {
        $( '#editor1' ).val( $( 'input#val' ).val() );
    }
</script>
</head>

<body>
<form id="f1" action="some.php" method="post" enctype="multipart/form-data">
<table>
    <tr>
        <td>Title:</td>
        <td><input type="text" name="articletitle" id="articletitle" required/></td>
    </tr>
    <tr>
        <td>Featured Image:</td>
        <td><input name="MAX_FILE_SIZE" value="2097152" type="hidden">
        <input name="image" id="image" type="file" required/></td>
    </tr>
    <tr>
        <td colspan="3"><textarea cols="80" id="editor1" name="editor1" rows="10"></textarea></td>
    </tr>
    <tr>
        <td><input id="save" type="submit" value="Save"></td>
    </tr>
</table>
</form>

<script type="text/javascript">

$(document).ready(function(){
    $("#save").click(function(){
        $("#f1").ajaxForm();
    });
});
</script>
</body>
</html>

请帮助我.

推荐答案

尝试一下:

$(document).ready(function(){
    $("#save").click(function(e){
        e.preventDefault();
        $("#f1").ajaxForm();
    });
});

这应该防止您的输入执行重定向页面的默认行为.

It should prevent your input from doing its default behavior of redirecting the page.

要重定向到另一个页面,您应该使用类似以下内容的

To redirect to another page you should use something like:

window.location.href = 'http://www.google.com';

关于ajax的成功事件.

on the ajax's Success event.

尝试这个小提琴: http://jsfiddle.net/4hF6e/3/确保您的参考是正确的.在我看来,AjaxForm插件可以通过某种方式来防止按钮上的默认行为.

Try this fiddle: http://jsfiddle.net/4hF6e/3/ Make sure your references are correct. Seems to me the AjaxForm plugin has some way to prevent default behavior on the button.

这篇关于我的ajaxForm重定向到PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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