WordPress.org

Ready to get started?Download WordPress

Forums

Ajax post not sending (1 post)

  1. MichaelWallis
    Member
    Posted 4 months ago #

    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.

Reply

You must log in to post.

About this Topic