I need to be able to pass data from a java-script script to php and send new data from the php script back to java-script. However, when I send the data to php and echo it in the new php script, the echoed content is sent through an alert.
A simplified (& incorrect) version of what I'm trying to do is as follows
index.php
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script src="script.js"> </script>
</head>
<body> </body>
</html>
script.js
$.ajax({ url: 'loadContent.php',
data: {action: 'HEYO'},
type: 'post',
success: function(output) {
alert(output);
}
});
loadContent.php
<?php
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
echo $action;
}
?>
What this code currently does is display an alert with whatever text is sent through script.js to loadContent.php. What I would like it to do is echo the content to the original page.
alert(output);It's doing what you're telling it to do.