简体   繁体   中英

Submitting post form via ajax, browser poup

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM