• I am trying to submit form data through an ajax request in my plugin but cant seem to get the post to send. Here is the post code:

    jQuery.ajax({
    
    					type:"post",
    					dataType:"json",
    					url: myAjax.ajaxurl,
    					data: {action: 'submit_data', info: info},
    					success: function(response) {
    						if (response.type == "success") {
    
    							alert("Success");
    						}
    						else  {
    
    							alert("Fail");
    						}
    					}
    				});

    And this is the function it should send the data to:

    add_action("wp_ajax_submit_data", "submit_data");
    	add_action("wp_ajax_nopriv_submit_data", "submit_data");
    
    	function submit_data() {
    
    		echo "<script> alert('hello'); </script";
    		header("Location: ".$_SERVER["HTTP_REFERER"]);
    
    		die();
    	}

    Upon submitting the data the javascript runs however when it gets to the ajax post nothing seems to happen, I do not get a ‘fail’, ‘success’ or ‘hello’ alert.

  • The topic ‘Ajax post not sending’ is closed to new replies.