0

私は持っている

<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 ?
    }
  });
4

3 に答える 3

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 応答を保存できます。

于 2012-12-27T03:47:07.480 に答える
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
    }
  });
于 2012-12-27T03:48:16.413 に答える
0
$.ajax({
   type: "POST",
   url: "the/form",
   data: $(\'.target\').serialize(),
   success: function(data) {
    //alert("done");
    $('#infoMessage').html(data);
    }
  });

ajax ファイル (the/form) にメッセージをエコーする必要があります。

于 2012-12-27T03:49:01.180 に答える