0v3k Shi3ld3r 0v3k Shi3ld3r - 4 months ago 7
Ajax Question

Echo Result From Ajax Call

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

Answer

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);