• Resolved danieltj

    (@danieltj)


    Hi, I’m trying to make a custom form element that uses AJAX to get some data from a form and when clicked, will do an AJAX request to run a function. However I’ve looked at all sorts of online guides and have nothing that makes any sense.

    Everything seems to be half complete and so when you try and put bits together, it just doesn’t work at all.

    Is there a full guide on how to implement this? It’s very frustrating because the AJAX and nonce docs aren’t complete enough to get a working example going. I’d update them myself but I’ve no idea how they work.

    Can someone help? I really don’t understand it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Have you seen the Ajax section of the Plugin Handbook yet? The example is pretty trivial, but all the parts work together. As you’ve found, getting everything working together can be quite a challenge. But once you figure it out for something trivial, you should be able to build upon that base and achieve something truly useful.

    Thread Starter danieltj

    (@danieltj)

    I’ll give it another go, but whenever I submitted my form it would go to admin-ajax.php and just show a white screen with the number 0 on it.

    Moderator bcworkz

    (@bcworkz)

    It sounds like your form is actually submitting data conventionally as opposed to Ajax script running. There should not be a true submit button or your jQuery event listener script needs to call event.preventDefault(). The submit button should look like one but not actually do anything itself, it’s just an object to add a listener to. Or if it’s a real button, it cannot be allowed to act normally.

    Thread Starter danieltj

    (@danieltj)

    Ah! Okay that’ll be why then. I’ll revisit the guide and see if I can get it working. I spent so much time looking at it that I didn’t realise that I can’t actually do anything to send the form to admin-ajax.php.

    Thanks, will give it another go.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using AJAX and Nonces for custom form’ is closed to new replies.