Web Analytics Made Easy -
StatCounter Javascript not working - CodingForum

Announcement

Collapse
No announcement yet.

Javascript not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript not working

    Hi,I am trying write a simple javascript But its not working I dont get any errors What am doing wrong again?


    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script type="text/javascript">
    
            function gonder() {
    
    
                $.ajax({
                    type: 'post',
                    url: 'ajax.php',
                    data: $('#ferman').serialize();
                success:function (msg) {
                    $('#sonuc').html(msg);
    
                }
            })
                ;
            }
        </script>
    </head>
    <body>
    <form id="ferman">
        <input type="text" name="ad">
        <input type="text" name="soyad">
        <input type="button" value="Gonder" onclick="gonder();">
    
    </form>
    <div id="sonuc"></div>
    </body>
    </html>
    this is ajax.php


    Code:
    <?php
    $ad=$_POST["ad"];
    $soyad=$_POST["soyad"];
    
    echo "$ad $soyad";
    
    ?>

  • #2
    Stick this in you ajax.php file
    PHP Code:
    /* Makes it so we don't have to decode the json coming from JQuery */
    header('Content-type: application/json'); 
    or use the json_decode on your variables -> PHP: json_decode - Manual

    I find doing it the first way is the best.

    I also find using the console's debug function in the browsers developers panel the best way to see what's going on then you can just use console.log(msg) instead of $('#sonuc').html(msg).
    Last edited by Strider64; Sep 28, 2016, 05:53 AM.
    "A person who never made a mistake never tried anything new." ~ Albert Einstein https://www.miniaturephotographer.com

    Comment


    • #3
      thank you friend

      Comment

      Working...
      X