javascript - Echoing to the screen using AJAX PHP -


i'm trying write short ajax code echo word 'hello' screen, far i'm not having luck. if know i'm doing wrong, please correct me, , let me know. thank you.

test6.html

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>  <script type = "text/javascript">   function myajax() {       $.ajax({            type: "post",            url: 'testing.php',            data:{action:'call_this'},            error: function(xhr,status,error){alert(error);},            success:function(html) {              alert(html);            }        }); }  </script>  <a href="#" onclick="myajax()">echo hello</a> 

testing.php

<?php  if($_post['action'] == 'call_this') {   echo "hello"; }  ?> 

i made little changes code, adding quotes 'action', , creating button because <a href has issues click event (buttons don't have issues), here is, works me, let me know if works :

<html>   <head>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>     <script type = "text/javascript"> function myajax () { $.ajax( { type : 'post',           data : {'action':'call_this'},           url  : 'testing.php',           success: function ( data ) {             document.getelementbyid( "my_div" ).innerhtml = data;           },           error: function ( xhr ) {             alert( "error" );           }         }); }     </script>   </head>   <body>     <a href="" onclick="myajax()">echo hello</a>     <br/><br/>     <button onclick="myajax()">echo hello</button>     <br/><br/>     <div id="my_div"></div>   </body> </html> 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -