php POST metod不使用jquery Ajax或不使用Ajax

php POST metod不使用jquery Ajax或不使用Ajax,php,jquery,ajax,post,server,Php,Jquery,Ajax,Post,Server,我在stackoverflow中搜索了这个问题,找到的答案很少,但没有一个对我有帮助。所以我再次发布它。我的php表单和localhost中的post方法工作正常,但相同的代码在服务器(linux服务器)中不工作。我不知道实际问题是什么。请帮助 我想提交的表格 名称 电子邮件 流动电话号码。 消息 “id=”captchaimgont“style=”右边距:14px;“alt=”验证码“> 在此处输入代码: 提交 我的jquery ajax代码 jQuery(文档).ready(函数

我在stackoverflow中搜索了这个问题,找到的答案很少,但没有一个对我有帮助。所以我再次发布它。我的php表单和localhost中的post方法工作正常,但相同的代码在服务器(linux服务器)中不工作。我不知道实际问题是什么。请帮助

  • 我想提交的表格
  • 
    名称
    

    电子邮件

    流动电话号码。

    消息 “id=”captchaimgont“style=”右边距:14px;“alt=”验证码“> 在此处输入代码:

    提交
  • 我的jquery ajax代码
  • jQuery(文档).ready(函数(){
    jQuery(“形式”).submit(函数(e){
    e、 预防默认值();
    e、 停止即时复制();
    jQuery('#sendmail').html('请稍候…');
    jQuery.ajax({
    类型:“post”,
    url:“./contact form.php”,
    数据:jQuery(“#forma”).serialize(),
    数据类型:“json”,
    成功:功能(数据){
    jQuery('p.error-red').html(“”);
    if('success'==data.result){
    //jQuery(“#forma”)[0].reset();
    //jQuery(“#response”).append(“

    ”+data.msg+”

    ”); //jQuery('#sendmail').html('Submit'); window.location.href=”https://www.mrpmediaworks.com/thanks.php"; } if('error'==data.result){ var arr=data.msg; var element_arr=data.fieldname; 计数='0'; 每个(arr,函数(索引,值){ 如果(value.length!=0){ jQuery('input[name='+element_arr[count]+']')).parent('.group').find('p.error-red').html(value); } 计数++; }); jQuery('#sendmail').html('Submit'); } } }); 返回false; }); });
  • 我的php代码


  • 这是我的htaccess文件中唯一的内容,只需创建一个函数来处理ajax请求。然后在函数中处理请求。为此

    从表单中删除操作。并在提交时将请求发送到功能上的参见下面的示例

     <form class="forma" id="forma" method="POST"  action="javascript:void(0);" name="myForm" autocomplete="off"  onsubmit="sendContactRequest();">
    

    请试试这个。在我的情况下,它工作得很好。

    我想你把你的htaccess文件弄糟了。如果可能的话,把你的.htaccess文件代码粘贴到这里

    编辑我的答案


    Bingo发现了您正在从文件中删除.php扩展名的问题,但在ajax请求中,您已将数据发布到contact-form.php。尝试从ajax请求中删除.php扩展名。尝试一下,希望这会有所帮助。

    您的表单在哪里,我在您的代码中看不到。@AnkitShah的副本实际上不是副本。他需要返回包含dat的jsona、 结果属性我没有发布我完整的php代码,但它有echo json_encode($result);但它不工作。我试图说我无法将数据从表单传递到php页面,该页面名为contact-form.php。我已经添加了我的htaccess代码。请看一看,并告诉我其中有什么错误。希望您能提供帮助
          4. .htaccess file
                    # browser requests PHP
                RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
                RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
    
               # check to see if the request is for a PHP file:
               RewriteCond %{REQUEST_FILENAME}\.php -f
               RewriteRule ^/?(.*)$ /$1.php [L]
    
     <form class="forma" id="forma" method="POST"  action="javascript:void(0);" name="myForm" autocomplete="off"  onsubmit="sendContactRequest();">
    
    function sendContactRequest(){
            jQuery('#sendmail').html('Please wait...');
            $.post("contact-form.php",jQuery("#forma").serialize(),function(result,status,xhr) { 
                if( status.toLowerCase()=="error".toLowerCase() ) { 
                    alert("An Error Occurred.."); // or do something that you can handle the error request.
                }else {  //success response
                }
            });
        }