/    Sign up×
Community /Pin to ProfileBookmark

AJAX: how to extract part of HTML from response

First, I’m much better with PHP than JavaScript.

I’m trying to come up with what is probably a kludge. What I’d like to do is take the responseText from an AJAX request — which will be a full HTML page — and parse it first to find if there is a <form>…</form> in it. If not I’ll display a success message and all is fine, but if it’s there, then I want to extract just that form section and display it within a <div> in the page.

This is where my JS skills are failing me. Can anyone point me to the applicable functions, tutorial, or whatever that would show me how to find the <form> and extract it and then replace my div contents with it (just innerHTML?).

Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@SpinnerApr 28.2010 — Do you use any ajax-library, like Prototype, Mootools or jQuery?
Copy linkTweet thisAlerts:
@NogDogauthorApr 28.2010 — Do you use any ajax-library, like Prototype, Mootools or jQuery?[/QUOTE]

At this point, no.

Currently, I'm thinking of a server-side solution, having my ajax form submission go to a PHP script with output-buffering, which will then include the existing form-handler, which I can then parse its buffered output via PHP's DOM classes and then process as I need.
Copy linkTweet thisAlerts:
@KorApr 28.2010 — try innerHTML...

But, wouldn't be simpler to do all this job (searching for <form></form> and sending only that form - with his elements - as a response or null if none) at the server-side level, in the PHP application to whom I suspect you are making that request?
×

Success!

Help @NogDog 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 5.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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