/    Sign up×
Community /Pin to ProfileBookmark

Hi All
is there a way to send an ajax request after submitting a form
i tried onsubmit event it flashes the list im trying to display after submitting(saving new records)

on my page i have:
menu
<div id=’x’>table to display selected menu + a button to add new recs</div>

what im trying to achieve is to refresh the list after adding new data

thanks in advance

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@MarPloMay 02.2011 — Hy,

You can submit that form data with Ajax, using a simple button, not submit, to call the Ajax function, which takes the form data and sends it, then receives the response, and you ca add to refresh the list.
Copy linkTweet thisAlerts:
@aj_nscMay 02.2011 — Like MarPlo stated, you cannot actually 'submit' the form fully, because that forces a page refresh. What you need is something like this:

<i>
</i>document.getElementById('myform').onsubmit = function(e) {

//do you ajax stuff here

//return false so the form doesn't actually get submitted
[B] return false;[/B]
};


[code=html]
<form id="myform">
....
<button type="submit">Submit</button>
</form>
[/code]
Copy linkTweet thisAlerts:
@wiss_devauthorMay 02.2011 — Thanks Guys

i allready have about 10 submit forms and i dont want to have to change them all. my idea was if there is an event to trigger an ajax function after the page refreshes
Copy linkTweet thisAlerts:
@aj_nscMay 03.2011 — Trigger an AJAX function after the page refreshes? Asking a question like that shows that there's a flaw in the logic of how things are being done.

AJAX requests are performed INSTEAD of page refreshes to communicate with the server without having the page reloaded. If your page is already being reloaded, then just do the server processing that you are planning on doing in your AJAX request at that time.
Copy linkTweet thisAlerts:
@wiss_devauthorMay 03.2011 — thanks for the replies

sorry I missexplained,i didnt mean refreshing the page but the div element where my submit form is being created via an ajax request

i input data into that form and then submit

now this div is blank

i have another button (AJAX) on the menu that creates a table in the same div

my goal is to call that function after the form being submitted rather then clicking the button
Copy linkTweet thisAlerts:
@aj_nscMay 04.2011 — Wait until you receive a response back from the form submission AJAX-request, and then just call the function that is called when you push the button on the menu......Really hard to suggest anything else without code or a link....hopefully that gives you an idea, though.
Copy linkTweet thisAlerts:
@wiss_devauthorMay 05.2011 — im creating the form in the div element using an AJAX request but the form itself in a post submit form

i will inbox you the link with login details so u know what i mean
Copy linkTweet thisAlerts:
@aj_nscMay 05.2011 — So I just checked out your interface. I think you're going to run yourself into a lot of trouble trying to turn the entire interface into being controlled by AJAX requests, unless you are highly organized from the get go. Page refreshes come in very handy at certain times, which I'm sure you'll come across.

In any case, for this specific issue, what I suggested earlier stands:

Submit the form using an AJAX request. When you get a response back from the server saying that the form submissions was successful, then issue the next ajax request that shows your user list - in other words - call getData(1,'users') and that will show your list again.
×

Success!

Help @wiss_dev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...