Support » Plugins » Hacks » Form with javascript/ajax does not work in WordPress

  • I use a template to hold a form. A plugin register javascript and jQuery. The form is processed by javascript/AJAX and sent to a PHP file to process its $_POST content and return it to the template page filling a <div>.

    I tried all the code before, without includin in my WordPress files works perfectly. The process php file returns HTML which is included in a <div> by ajax script.

    The same code does not work in wordpress. Firebug shows that javascript is working, the form is emptied but the result never gets back. I wonder about html() method, but it works without WordPress.
    Any suggestions?

    I include 4 files: template, plugin php, javascript file and process file.

Viewing 3 replies - 1 through 3 (of 3 total)
  • There was an error with url, so process php file was not found. I will put some code to correct this.

    Neverteheless data is returned 0, any suggestions?"../wp-content/plugins/itm_simple_paypal_process.php",jQuery(form).serialize(), function(data){
            // place some code to find plugin directory
    	jQuery ('#destino').html(data);  // fills the div with data
    	alert(data); // data appears on alert window
    Moderator bcworkz


    I’m not sure why, but conventional AJAX seems to be problematic in WordPress, as you have discovered. I suggest you restructure your code to submit the form via admin-ajax.php, which means enqueuing your script via the ‘admin_enqueue_scripts’ action, even for front end related code. The server response is then implemented by hooking the action defined in part by the ‘action’ value passed by See AJAX in Plugins for more detailed information on this approach.

    Thanks, really it seems this the case. I have to reformulate the code to some AJAX guidelines for WordPress. I am using as guidelines this three pages:
    A simple example, that helps me to understand it …
    Codex itself
    A few tips

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Form with javascript/ajax does not work in WordPress’ is closed to new replies.