-2

所以我的ajax成功功能没有加载。所以我不知道它有什么问题。有什么办法可以检查吗?和 mysql_error() 一样吗?现在,如果你们能弄清楚它有什么问题,或者另一端的 PHP 有什么问题,那就太好了。

jQuery.ajax({
   type: "POST",
   url: "http://mywebsite.net/snippetsave.php",
   data: {id: snippetID, name: snippetName, content: snippetContent},
   cache: false,
   success: function(response){
        loadsnippet(snippetID);
        $("body").attr("saved", "yes");
        $("a[snippetid='" + snippetID + "']").addClass("saved");
   }
 });

和片段保存.php:

<?php
session_start();
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$connect = mysql_connect(......);
$select_db = mysql_select_db(.....);
if(!$connect){ 
die(mysql_error()); 
} 
$currentsnippet = mysql_escape_string($_POST['id']);
$snippetnames = mysql_escape_string($_POST['name']);
$snippetcontents = mysql_escape_string($_POST['content']);
$update = mysql_query("UPDATE newsnippets SET name='$snippetnames', content='$snippetcontents' WHERE id='$currentsnippet'");
if (!$update){
die(mysql_error());
}
?>
4

2 回答 2

1

尝试添加错误处理函数:

jQuery.ajax({
   type: "POST",
   url: "http://mywebsite.net/snippetsave.php",
   data: {id: snippetID, name: snippetName, content: snippetContent},
   cache: false,
   success: function(response){
        loadsnippet(snippetID);
        $("body").attr("saved", "yes");
        $("a[snippetid='" + snippetID + "']").addClass("saved");
   },

   error: function(response) {console.log(response);}
 });
于 2013-10-20T00:52:59.307 回答
0

您可以在 jQuery.ajax 方法中添加回调方法

jQuery.ajax({
    type: "POST",
    url: "http://mywebsite.net/snippetsave.php",
    data: {id: snippetID, name: snippetName, content: snippetContent},
    cache: false,
    success: function(response){
             loadsnippet(snippetID);
             $("body").attr("saved", "yes");
             $("a[snippetid='" + snippetID + "']").addClass("saved");
    },
    error:function(){
            // error handler
    }
});
于 2013-10-20T01:01:12.240 回答