Answers for "jquery ajax data with formdata and other variables"

PHP
4

formdata jquery ajax php

//set your ajax url here
//$url = 
$(document).on('submit', '#form',  function(e){
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: $url,
            data: new FormData(this),
            dataType: 'json',
            contentType: false,
            processData:false,//this is a must
            success: function(response){ 
                //statements on success
            }
        });
    });
Posted by: Guest on June-11-2021
0

form append other data feild and send through ajax

var data = new FormData();
data.append('name', 'Bob'); 

function sendData() {
    $.ajax({
        url: '/helloworld',
        type: 'POST',
        contentType: false,
        data: data,
        dataType: 'json'
    });
}
Posted by: Guest on July-08-2021

Browse Popular Code Answers by Language