Support

Account

Home Forums Front-end Issues Ajax font-end save stopped working? Reply To: Ajax font-end save stopped working?

  • Hey John, I was able to solve this by moving the ajax save completely into my own function. Here is the function in case anyone finds this later:

    $('.acf-form').on('submit', function(e){
            e.preventDefault();
    		
    		// define the form data
    		let $form = $(e.target);
    		
    		// submit the form
    		$.ajax({
    			url: window.location.href,
    			method: 'post',
    			data: $form.serialize(),
    			success: function(data) {
    					$("a.save").removeClass("saveActive");
    					$("a.save").addClass("saveComplete");
    					$("a.save i").removeClass('fa-spinner');
    					$("a.save i").addClass('fa-thumbs-up');
    					$("#saveText").html("Saved");
    					
    					setTimeout(function(){
    						$("a.save").removeClass("saveComplete");
    						$("a.save i").removeClass('fa-thumbs-up');
    						$("a.save i").addClass('fa-save');
    						$("#saveText").html("Save");
    					}, 3000);	
    			}
    		});
    		console.log("form submit 1");
    	});

    I don’t know why it stopped working. Something about the e.preventDefault() stopping this:

    acf.add_action('submit', function($form){
    		
        // old ajax code was in here
    		
    	});