? Javascript POST? ???? ?? ??: Javascript ??? PHP? ??? ?????
Oct 30, 2024 pm 03:48 PMJavascript POST? ???? ??: Javascript ??? PHP? ???
??? ???? ???? JavaScript ??? PHP? ???? ? ??? ??????. POST? ?? PHP ????. ? ??? ???? ?? ??? ???? ?? ??? ?????.
JavaScript:
function sendToPHP() { $.post("index.php", { "variable": toSearchArray }); }
PHP:
<?php $myval = $_POST['variable']; print_r ($myval); ?>
?? ??:
AJAX(Asynchronous JavaScript and XML) ?? ??? ?? ??? ?? ??? ??? ? ????. jQuery? AJAX ??? ?????? ????? ?? ??? ??? ?????.
??? ?? sendToPHP() ??? toSearchArray? ??? ?? ????? ???? index.php ???? ?? POST ??? ??????. ??? ??? ??? ????? AJAX ?? ??? ??? ???? ?? ?????.
index.php? ???? ?:
<html> <head> <title>Test</title> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#btn').click(function(){ var txt=$('#txt').val(); if(txt == ''){ alert("Enter some text"); } else { $.post('catcher.php', {'text':txt}, function(data){ $('#response').text(data.message); }, 'json'); } }); }); </script> </head> <body> <input type="text" id="txt"> <input type="button" id="btn"> <pre id="response" style="overflow:auto;width:800px;height:600px;margin:0 auto;border:1px solid black;">