/    Sign up×
Community /Pin to ProfileBookmark

Struture for a widget occuring on page multiple times

I’m just writing a simple plug-in that will fill in div placeholders in the page body, on page load, with info fetched from a database via AJAX. It’s all working, but I have reservations over it’s efficiency and whether place1 will always show cake1 and place2 always cake2 due to the asynchronicity of AJAX.

So simplifying:

[CODE]
<body onload=”show_recipe(‘place1’, ‘cake1’); show_recipe(‘place2’, ‘cake2′)”>

<div id=’place1′></div>
<div id=’place2’></div>
[/CODE]

and

[CODE]
function show_recipe(place, food) {

function recipe_received() {
// Manipulate DOM…
}

send_off_db_request(food, recipe_received)
}
[/CODE]

Is there a better way to structure this?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @julie_c 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.20,
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,
)...