0

I'm trying to submit my classic post content form via javascript like this. I want to just publish/update wp post but from different button then classic wp-publish box.

publishPost: ->
    $('.tome-publish').click ->
        $('form#post').submit()

        location = window.location.href;
        location += ( location.indexOf( '?' ) != -1 ) ? '&' : '?';
        location += 'wp-post-new-reload=true';
        window.history.replaceState( null, null, location );
        console.log( window.history );

but whe the forms submit browser asks me

The changes you made will be lost if you navigate away from this page.

Are you sure you want to leave this page?

do you know what to do to get rid of this javascript nag? Thank you.

Jakub Kohout
  • 1,854
  • 3
  • 21
  • 36

2 Answers2

1

when you use .submit() its synchronous form submit it is same as normal form submit. if you want to do an ajax post use $.ajax instead

0

it's hard to know for sure without seeing more of your code, but I wonder if you're allowing other listeners to process the click event after you handle it in your listener. Here's a Stack Overflow link talking about event.preventDefault() and event.stopPropagation() which might come in handy here.

Community
  • 1
  • 1
Dan O
  • 6,022
  • 2
  • 32
  • 50