/    Sign up×
Community /Pin to ProfileBookmark

How do you use links with ajax. If I want to click on a link and it needs to goto a ajax function call how do i do that.
I am reciving the link from a php script called by ajax.

echo “<a href=’viewPhoto1.php?pageNo=”.$i’>”.$i.”</a>”; //i want to call an ajax function instead of php.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@pcx99Feb 09.2007 — How do you use links with ajax. If I want to click on a link and it needs to goto a ajax function call how do i do that.

I am reciving the link from a php script called by ajax.

echo "<a href='viewPhoto1.php?pageNo=".$i'>".$i."</a>"; //i want to call an ajax function instead of php.[/QUOTE]


<i>
</i>&lt;a href='someurl' onclick="ajaxFunction(); return false"&gt;Link Text&lt;/A&gt;


If the user doesn't have javascript enabled or the browser shuts down the script because it caught an error then the link will actually clickthrough to "someurl". If you really want the link to go nowhere -- EVER replace 'someurl' with '#' then nothing will happen if the user doesn't have javascript.

If the user does have javascript when the link is clicked it will call "ajaxFunction()", the return false tells the browser to ignore the href value.

Hope that helps you out a bit.
×

Success!

Help @jagguy 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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