Jump to content

martin27

New Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by martin27

  1. For making simple "POST" in ajax and get the response ,i am describing here a good example as tested:

     

    Step-1:

    Make a html form for the same which you have to sent with using ajax for server:

     

    <form id="foo">

        <label for="bar">A bar</label>

        <input id="bar" name="bar" type="text" value="" />

     

        <input type="submit" value="Send" />

    </form>

     

    Step-2:

     

    Here i am using a function which is related to your requirement:

     

    <script type="text/javascript">

    // Variable to hold request

    var request;

     

    // Bind to the submit event of our form

    $("#foo").submit(function(event){

     

        // Abort any pending request

        if (request) {

            request.abort();

        }

        // setup some local variables

        var $form = $(this);

     

        // Let's select and cache all the fields

        var $inputs = $form.find("input, select, button, textarea");

     

        // Serialize the data in the form

        var serializedData = $form.serialize();

     

        // Let's disable the inputs for the duration of the Ajax request.

        // Note: we disable elements AFTER the form data has been serialized.

        // Disabled form elements will not be serialized.

        $inputs.prop("disabled", true);

     

        // Fire off the request to /form.php

        request = $.ajax({

            url: "/form.php",

            type: "post",

            data: serializedData

        });

     

        // Callback handler that will be called on success

        request.done(function (response, textStatus, jqXHR){

            // Log a message to the console

            console.log("Hooray, it worked!");

        });

     

        // Callback handler that will be called on failure

        request.fail(function (jqXHR, textStatus, errorThrown){

            // Log the error to the console

            console.error(

                "The following error occurred: "+

                textStatus, errorThrown

            );

        });

     

        // Callback handler that will be called regardless

        // if the request failed or succeeded

        request.always(function () {

            // Reenable the inputs

            $inputs.prop("disabled", false);

        });

     

        // Prevent default posting of form

        event.preventDefault();

    });

    </script>

      

     Now You can access the values posted by jQuery.ajax through the global variable $_POST, like this:

     

     $bar = $_POST['bar'];

     

     

     You could also use the shorthand .post in place of .ajax in the above JavaScript code:

     

    <script type="text/javascript">

     $.post('/form.php', serializedData, function(response) {

        // Log the response to the console

        console.log("Response: "+response);

    });

     </script> 

  2.  $prix should be a numeric value which contains only numbers no special characters allowed.

       

    For example :

     

    $prix = 12345;  not as $prix = $12345

     

    $prix = number_format($prix, 2, '.', ' ');

        if($prix != 0)

        echo '<p class="p_prix_info_ann"><span class="vert">'. $language['page_ann_prix'] .' :</span> '. $param_gen['devise'] .' '. $prix .'</p>';

     

     

    which gives :  12 345.00 when $prix is 12345

  3. Hi,

    This is Martin. I'm new to this forum. I'm an experienced PHP developer and having more than 5 years of experience in PHP development and programming solutions. I would like to share my thoughts with other PHP developers here.


    Thanks in advance

    Martin
     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.