Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jqueryajax函数总是返回false_Php_Jquery_Ajax - Fatal编程技术网

Php jqueryajax函数总是返回false

Php jqueryajax函数总是返回false,php,jquery,ajax,Php,Jquery,Ajax,我的JS和PHP文件都能正常工作,我遇到的问题是,即使我看到PHP脚本导致输出“继续”,它也总是说提交错误。数据库插入在表单中正常工作,count存储我的表中的行数。有什么是我忽略的吗 JS 您可能会在“继续”响应中输出空格或其他字符,这将使成功处理程序中的条件为false。var-dataString=$(“form”).serialize(); var dataString = $("form").serialize(); var msg = '<?php echo $msg; ?&g

我的JS和PHP文件都能正常工作,我遇到的问题是,即使我看到PHP脚本导致输出“继续”,它也总是说提交错误。数据库插入在表单中正常工作,count存储我的表中的行数。有什么是我忽略的吗

JS
您可能会在“继续”响应中输出空格或其他字符,这将使成功处理程序中的条件为false。

var-dataString=$(“form”).serialize();
var dataString = $("form").serialize();
var msg = '<?php echo $msg; ?>';

$.ajax({
    type: "POST",
    url: 'submit_form.php',
    data: dataString,
    dataType: 'html',
    error: function() {
        alert('Error');
    },
    success: function(msg) {
        if (msg == 'proceed') {
            $('#contact_form').html("<div id='message'></div>");
            $('#message').html("<h2>Contact Form Submitted!</h2>").append("<p>We will be in touch soon.</p>");
        }
        else {
            $('#contact_form').html("<div id='message'></div>");
            $('#message').html("<h2>Error with Submission!</h2>").append("<p>Please Try again.</p>");
        }
    }
});
return false;​
var msg=''; $.ajax({ 类型:“POST”, url:'submit_form.php', 数据:dataString, 数据类型:“html”, 错误:函数(){ 警报(“错误”); }, 成功:功能(msg){ 如果(消息==‘继续’){ $(“#联系方式”).html(“”); $('#message').html(“已提交联系表单!”)。追加(我们将很快联系。

); } 否则{ $(“#联系方式”).html(“”); $(“#message”).html(“提交错误!”)。追加(请重试。

); } } }); 返回false;​

试试这个?

试试这个:用修剪来清理响应

success: function(msg) {
    if ($.trim(msg) == 'proceed') {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>").append("<p>We will be in touch soon.</p>");
    }
success:函数(msg){
如果($.trim(msg)=‘继续’){
$(“#联系方式”).html(“”);
$('#message').html(“已提交联系表单!”)。追加(我们将很快联系。

); }
我看到的两个最常见的原因是ajax可能总是运行错误方法

 dataType=json
如果不是json,请删除此行

  async : true

考虑改变一下,我也遇到了同样的问题,错误在php而不是ajax中


在submit_form.php顶部定义$MySQLi并重试;)

return false
始终返回false..php格式有什么问题?在函数(msg)中添加一个警报(msg){也可以看到响应..@Esailija您明白了,即使数据是“继续”的,else条件块也会运行有没有理由不在表单API中使用drupal的AHAH或AJAX(d7)?它不应该是
“html”
,它应该是
“text”
。这在技术上与他已经拥有的相同,因为拼写错误的
数据类型
,类型是从服务器发送的内容类型头推断出来的,默认情况下是
文本/html
 dataType=json
  async : true