doudi4137 2012-01-11 12:14
浏览 231
已采纳

如何在不刷新页面的情况下发送表单?

I don't know PHP.

I don't want the user to go to http://www.example.com/feedback-thanks.html after sending the form. What I want is text below the sent button or anything without refreshing the page.

I removed header( "Location: http://www.example.com/feedback-thanks.html" ); but i don't receive the e-mail and the user is redirected to feedback.php... :(

html

<form method="post" action="feedback.php">
<input name="email" type="email"/>
<textarea name="message" id="feedback-textarea" autofocus="autofocus" required="required" ></textarea>
<button type="submit" id="feedback-button-send">send</button>
</form>

feedback.php

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "abcde@gmail.com", "Subject Here",
    $message, "From: $email" );
  header( "Location: http://www.example.com/feedback-thanks.html" );
?>
  • 写回答

4条回答 默认 最新

  • doutuo1939 2012-01-11 12:16
    关注

    You will have to use $.ajax() for that

    this is what I use in one of my apps

    $('#submitSearch').click(function() {
    
            var formData = {
                searchData: $('#searchData').val(),
            };
    
            $.ajax({
                url: siteUrl + 'fetch/search',
                type: "POST",
                data: formData,
                cache: true,            
                beforeSend:function(){
                    jQuery('#main').html('<div class="loading"><img src="' + siteUrl + 'resources/imgs/ajax-loader.gif" alt="Loading..." /></div>');
                },
                success: function(data) {
                    jQuery('#main').empty();
                    jQuery('#main').append(data);
                },
                error:function(x,e){
                    if(x.status==0){
                        alert('You are offline!!
     Please Check Your Network.');
                    }else if(x.status==404){
                        alert('Requested URL not found.');
                    }else if(x.status==500){
                        alert('Internel Server Error.');
                    }else if(e=='parsererror'){
                        alert('Error.
    Parsing JSON Request failed.');
                    }else if(e=='timeout'){
                        alert('Request Time out.');
                    }else {
                        alert('Unknow Error.
    '+x.responseText);
                    }
                }
            });
            return false;
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码