成功显示消息的jquery表单从服务器生成

时间:2012-12-27 03:45:53

标签: jquery

我有

<div id="infoMessage" class="infoMessage"><?php echo $message;?></div>

在POST时,$ message将从服务器生成。

如果我想在ajax成功后显示infoMessage,该怎么办

 $.ajax({
   type: "POST",
   url: "the/form",
   data: $(\'.target\').serialize(),
   success: function() {
    alert("done");
    // how to show the infoMessage ?
    }
  });

3 个答案:

答案 0 :(得分:0)

 $.ajax({
   type: "POST",
   url: "the/form",
   data: $(\'.target\').serialize(),
   success: function(data) { // data is a callback variable which stores info echoed in PHP file during transfer, so you have to $message there to get it here
    alert(data); // this will alert it
    }
  });

这里有功能(数据)你可以使用任何变量来存储AJAX响应

答案 1 :(得分:0)

尝试使用以下代码而不是您拥有的代码。

$.ajax({
   type: "POST",
   url: "the/form",
   data: $(\'.target\').serialize(),
   success: function(data) {
    alert(data); //data contains the ajax response
    $("#infoMessage").html(data); //you set here where to ajax response will be displayed
    }
  });

答案 2 :(得分:0)

$.ajax({
   type: "POST",
   url: "the/form",
   data: $(\'.target\').serialize(),
   success: function(data) {
    //alert("done");
    $('#infoMessage').html(data);
    }
  });

您必须在您的ajax文件(/ form)

中回显该消息
相关问题