来自Ajax调用的回声结果

时间:2016-07-17 12:27:16

标签: php jquery ajax

如何在页面index.php上显示回显的结果,脚本执行action.php

示例index.php调用action.php(AJAX)一旦所有成功,action.php将回显一些文本。然后index.php显示了

 <script>
// initiate the document for data
 $(document).ready (
   function()
   {
// I declare here id of object and action event
$('#msg').on('click', function() {

//to disable button after click
// code here for disable button


var info = $('#name').val();
$.ajax({
method: "POST",
url: "actions/action_comment.php",
//pass my variables to ajax - jq here in data name:
data: {

//id is id of the profile you are viewing eg , who the comment is for
name: info, recptid: '<?php echo $_GET["id"]; ?>'  , 

//que is the username of the profile you are viewing (not you) eg name of person comment is for
name: info, q: '<?php echo $userrecivmsg; ?>' , 

// myid is the id OF YOU  eg id of person sending the comment
name: info, myid: '<?php echo $myid; ?>' , 

// me is the username of YOU eg name of person sending the comment
name: info, me: '<?php echo $usersendingmsg; ?>'
},

         //feed the success my data to return results
    success: function(data){

            $('#data').append(status);

              //ON THIS LINE I WOULD LIKE TO HAVE TEXT DISPLAYED ONLY NOT AS AN ALERT OR DIALOG BOX
               window.alert(data);
               $('#data').val('Sent');

    } // end 
    }); // end

       // STOP DEFAULT BEHAVIOR
      return false;

   }); // end
   }); // end
        </script>

我在window.alert中获得它的那一刻但是我想没有警报只是文本出现在echo.php的index.php上

{{1}}

再次感谢并再次感谢

1 个答案:

答案 0 :(得分:0)

在index.php中添加要显示结果的元素

示例<div id="showResult"></div>

然后在success function in ajax

$("#showResult").text(data);