dongtaogou6226 2016-07-17 12:27
浏览 22
已采纳

来自Ajax调用的回声结果

How can one have the results of an echo display back on the page index.php where the script executes the action.php

Example index.php calls action.php (AJAX) once all is successful action.php will echo some text . Then index.php has this displayed

window.alert(data);
$('#data').val('Sent');

A the moment I have it in a window.alert but I would like no alert just text appear on the index.php from the echo action.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>

Thanks and Thanks again

  • 写回答

1条回答 默认 最新

  • dougu9895 2016-07-17 12:30
    关注

    Add an element in your index.php where you want to display the result

    example <div id="showResult"></div>

    Then in your success function in ajax

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?