2

I'm working on a wordpress editor for my blog, and need to be able to make sure that the function doGET() is finished before I click the save button with javascript or jquery. The doGET function might take a tad of time as I'm in a country with incredible slow internet connection...

$('#xmlbutton').click(function() { doGET(); document.getElementById("save-post").click(); }) 
1

1 Answer 1

3

You have to put...

document.getElementById("save-post").click(); 

in the callback of doGET() since it's an asynchronous operation.

Since I don't have all your code I made a little example.

$('#xmlbutton').on('click', function(){ $.get('/post/edit', {"id":"12"}, function(result){ $('#save-post').trigger('click'); }) }); 

PS: Instead of $('#save-post').trigger('click'); you should probably do $('#save-post-buttons-form').trigger('submit');.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.