Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ajaxpost

/* Attach a submit handler to the form */
$("#foo").submit(function(event) {
     var ajaxRequest;

    /* Stop form from submitting normally */
    event.preventDefault();

    /* Clear result div*/
    $("#result").html('');

    /* Get from elements values */
    var values = $(this).serialize();

    /* Send the data using post and put the results in a div */
    /* I am not aborting previous request because It's an asynchronous request, meaning 
       Once it's sent it's out there. but in case you want to abort it  you can do it by  
       abort(). jQuery Ajax methods return an XMLHttpRequest object, so you can just use abort(). */
       ajaxRequest= $.ajax({
            url: "test.php",
            type: "post",
            data: values
        });

      /*  request cab be abort by ajaxRequest.abort() */

     ajaxRequest.done(function (response, textStatus, jqXHR){
          // show successfully for submit message
          $("#result").html('Submitted successfully');
     });

     /* On failure of request this function will be called  */
     ajaxRequest.fail(function (){

       // show error
       $("#result").html('There is error while submit');
     });
Comment

PREVIOUS NEXT
Code Example
Javascript :: new date is not working in react js 
Javascript :: ticket 
Javascript :: How to Solve the Staircase Problem with 5 Lines of JavaScript 
Javascript :: how to cut and paste an element in vanilla javascript 
Javascript :: frontend backend communication 
Javascript :: pass data between componets in react 
Javascript :: Use a stack to convert the infix expression x*y-2 into post-fix 
Javascript :: react native scan network 
Javascript :: Quick JS DATE 
Javascript :: Register Multiple Models In Admin 
Javascript :: upload file to s3 using pre signed url javascript 
Javascript :: what is container in angular 
Javascript :: how to confirm if angular js in installed 
Javascript :: Bootstrap 5 data attributes different from Bootstrap 4 
Javascript :: js Changing selected option by option id, class, or attribute 
Javascript :: req.session undefined express node js 
Javascript :: loading indicator react native 
Javascript :: difference between usecallback and usememo 
Javascript :: router.put method 
Javascript :: javascript function counting cards 
Javascript :: setCount 
Javascript :: Why is node creating multiple server in cpanel 
Javascript :: if this then this, else that 
Javascript :: react onwheel preventDefault 
Javascript :: MAP METHOD. IMPORTANT 
Javascript :: js remove child with index 
Javascript :: angularjs Both ng-model and ng-change on input alter the $scope state - which one takes priority 
Javascript :: angularjs Ionic styling container 
Javascript :: How to spread state into a specific array 
Javascript :: arrow function - one line and no parameters 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =