www.webdeveloper.com
Results 1 to 3 of 3

Thread: JQUERY AJAX POST how to pass the var

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    68

    JQUERY AJAX POST how to pass the var

    hi i'm working on an ajax response but i'm just confuse on how will i get the return data of the response.

    here's the code


    Code:
    $(document).ready(function () {
    
        $('#submit').click(function () {
               function access(postcodes,submits){
                    $.ajax({
                        type: "POST",
                        url: "index.php",
                        data: { 'submit':submits, 'postcode': postcodes },
                        success: function (data,status) {
                            reuturn 
                        }
                    });
               }
    
               var submits = $('#submit').val();
               var postcodes = $('#postcode').val();
               access(postcodes, submits);
    	
        });
    
    
    
    });
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

    <script src="ajax.js"></script>

    <form method="POST" action="">
    insert postcode:<input type="text" id="postcode" name="postcode">
    <input type="button" id="submit" name="submit" value="submit">
    </form>


    PHP Code:
    <?php
    if($_POST['submit']=="submit"){
        if(
    $_post['postcode']){
    echo 
    "this is the value";
    }

    }
    ?>
    what do i need to do to get the return??

  2. #2
    Join Date
    Apr 2011
    Posts
    68
    what syntax do i need, to get the value of php?

  3. #3
    Join Date
    Mar 2014
    Posts
    1
    When you click Sumit to ajax, you can press F12 to view the request and response in Console if you use FireFox, and in Network if you use Chrome.
    the response data you will receive if your code is true :
    "this is the value"
    It's a javascript object, it's not a php object, so you should use javascript function to use the response.
    Ex:
    ...success: function (data,status) {
    $('#test').html(data);
    }....

    <div id= "test"></div>

    Check and reply

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles