【问题标题】:Error while inserting data into database using with ajax,php使用ajax,php将数据插入数据库时​​出错
【发布时间】:2016-05-25 22:03:38
【问题描述】:

使用 ajax、php 和 jquery 将数据插入数据库时​​出错,适用于本地主机,但上传到服务器后会出错。

$('#sunsubmit').click(function(){
    var insertedvalue = $('#sundayform').serialize();
    $('form#sundayform').unbind('sunsubmit');
    $.ajax({
        type: "POST",
        url: "routineinsert/sunday.php",
        data: insertedvalue,
        beforeSend: function(messageinfo){},
        success: function(messageinfo){ 
            var c = customalertbox.render("Message!!",messageinfo);
            progressdiv.style.display="none";},
        error: function(jqxhr) {
            customalertbox.render(jqxhr.responseText);
        }
});

它适用于我的计算机,但对于服务器,它甚至没有重定向到插入代码所在的星期日文件,它直接调用错误函数。

【问题讨论】:

  • 请出示您的代码以了解您的问题
  • 您的应用配置可能有问题。
  • $('#sunsubmit').click(function(){ var insertedvalue = $('#sundayform').serialize(); $('form#sundayform').unbind('sunsubmit '); $.ajax({ type:"POST", url:"routineinsert/sunday.php", data:insertedvalue, beforeSend:function(messageinfo){}, 成功: function(messageinfo) {var c =customalertbox.render ("Message!!",messageinfo); progressdiv.style.display="none";}, error: function(jqxhr) {customalertbox.render(jqxhr.responseText);} });
  • 请编辑您的问题并将您的代码粘贴到那里。您是否根据生产服务器更改了 php 上的数据库服务器 ip?
  • 可能你的ajax请求的url参数有问题。

标签: javascript php ajax web


【解决方案1】:

您的成功函数似乎缺少左大括号:

success: function(messageinfo) 

应该是

success: function(messageinfo) {

如果您始终注意格式,则更容易注意到这一点:

    success: function(messageinfo)  <============
        var c = customalertbox.render("Message!!",messageinfo);
        progressdiv.style.display="none";
    },
    error: function(jqxhr) {
        customalertbox.render(jqxhr.responseText);
    }

【讨论】:

  • 加上左括号会出现同样的错误......它适用于本地主机,但在将其上传到服务器后不适用于服务器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-07
  • 2017-11-20
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多