PHP unable to receive Javascript variable via Ajax -
solved: didn't realize ajax sent data in instance , redirecting created new instance.
i looked through stackoverflow results none of works.
i trying send variable mmm php via post , reason php doesnt retrieve it. don't know doing wrong.
here javascript code (in file checks.js):
$.ajax({ type: "post", url: 'https://www.example.com/panel/app.php', data: {mmm: 145}, success: function(data) { alert("success"); } }); document.getelementbyid("adminloginform").submit();
here php code in file (app.php):
<?php $output = (isset($_post['mmm'])) ? $_post['mmm'] : 0; echo "<script>console.log( 'debug objects: " . $output . "' );</script>"; ?>
google console log prints: "debug objects: 0"
the file directory follows:
main folder
base
registration
login
base
js
- checks.js
panel
- app.php
ajax means not doing form submission browser action, refreshes page. try rid of line , run code document.getelementbyid("adminloginform").submit();
. may alert success.
$.ajax({ type: "post", url: 'https://www.example.com/panel/app.php', data: {mmm: 145}, success: function(data){ alert("success"); console.log( 'debug objects: ' + data ) } });
and change php script echo $output.
Comments
Post a Comment