Trying to figure out Ajax. Help me find the file :( It should work like this: enter text in one input, output to another. And in my second page content is stupidly written (

<script language="javascript" type="text/javascript"> <!-- function ajaxFunction1(){ $.post("task12.php", { "in" : $("#in1").val()}, function(data){ $("#out1").val(data); }, "text"); } --> </script> Demo post metod<br> Input text: <input type="text" onkeyup="ajaxFunction1();" name="in1" id="in1" /> ajax result: <input type="text" name="out1" id="out1" /> </form> 

Added.

task12.php:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> Task12</title> <link href="style7.css" rel="stylesheet"> <script type="text/javascript" src="jquery.min.js"></script> </head> <script language="javascript" type="text/javascript"> <!-- function ajaxFunction1(){ $.post("task10.php", { "in" : $("#in1").val()}, function(data){ $("#out1").val(data); }, "text"); } --> </script> <body> <form> Demo post metod<br> Input text: <input type="text" onkeyup="ajaxFunction1();" name="in1" id="in1" /> ajax result: <input type="text" name="out1" id="out1" /> </form> </div> </body> </html> 
  • Show task12.php - Boolean
  • Question! $ .post ("task12.php", {"in": $ ("# in1"). val ()} Why then do you have HTML in the task12.php file? You should simply process the data in this file and send them back. - Artem Nov.
  • @Shrek, just about, but here you don’t even know what it has) task12.php -> task10.php - Boolean
  • @shrek, @Boolean I thought that there is writing the name of the file of the page in which the box. Or need another? This is me testing. Put task10.php. There should generally be a task12. Still not working. - Timmi55
  • There's just bare PHP, which gets data from you and then sends it back, no HTML should be there! An example in the answer last! - Artem Nov.

2 answers 2

On the client side:

 $.post( "/ajaxtest.php", { param1: "param1", param2: 2 }, onAjaxSuccess ); function onAjaxSuccess(data) { // Здесь мы получаем данные, отправленные сервером и выводим их на экран. alert(data); } 

On the server side, no HTML:

 <?php // файл http://hostname/ajaxtest.php echo "I get param1 = ".$_POST['param1']." and param2 = ".$_POST['param1']; ?> 

In response, you will get the string I get param1 = param1 and param2 = 2 .

    Apparently, in task12.php you have the whole page displayed, and not just the result. This can happen, for example, when using a template engine. Make sure that you have displayed only the desired value, without any <html> -influx. Or extract the value from the item from the answer page:

     data = $(data).find('#content').html(); $("#out1").val(data); 
    • in task12.php itself is a page with a form and a script. is it supposed to be? - Timmi55
    • Only SCRIPT. - Artem Nov.
    • @ Timmi55, there should be nothing at all, except for the desired value. - ling