How to create multiple ajax calls in jQuery in more efficient and useful way?

Add a data-id attribute to your link and use one piece of JS.

Add a data-id attribute to your link and use one piece of JS: link 1 link 2 link 3 $("ul li a"). Click(function() { var idToSend = $(this). Data('id'); $.

Get("anothertest. Php? Q=" + idToSend, function(data){ $("#phpTestAlon").

Html(data); }); }); This example uses data-id, but you could use any attribute you wanted, including id="". Another sensible option would be rel="". Notice the selector has changed to ul li a so as to capture all clicks in one event.

– Amir Raminfar Dec 3 '11 at 23:10 @AmirRaminfar Because then the browser thinks the points to thedomain/1 if we have href="1"; it treats it as a normal link. – JamWaffles Dec 3 '11 at 23:13 Not not at all what I mean. Look at my answer.

I would put the whole url in the href like so href="anothertest. Php? Q=2".

Less code. Better usability. Still works if js is disabled.

Every body is happy. – Amir Raminfar Dec 3 '11 at 23:14 @AmirRaminfar Because then the link would just redirect to a new page. The OP is asking about AJAX.

– JamWaffles Dec 3 '11 at 23:17.

This is a solution to the problem the OP is describing, but it's better to solve the cause of the problem, than work around the problem itself. No disrespect, just some friendly advice :-) – JamWaffles Dec 3 '11 at 23:22.

You can do $("ul li a"). Click(function() { e.preventDefault() $. Get(this.

Href, function(data){ $("#phpTestAlon"). Html(data); }); }); With this HTML: link 1 link 2 link 3 It is important that this solution also works if javascript is disabled. Return false will make sure if js is enabled to not actually go to a different page.

But if js was disabled, then the user would just go to whatever linked they clicked on.

Return false is bad. Why aren't you using e.preventDefault()? – JamWaffles Dec 3 '11 at 23:17 Why is it bad?

I actually find this easier to read. – Amir Raminfar Dec 3 '11 at 23:19 It's bad, and it isn't; I don't see e.preventDefault() anyehere in your answer. – JamWaffles Dec 3 '11 at 23:21 I respectfully disagree with that answer.

I prefer have jQuery cancel the event instead of me. – Amir Raminfar Dec 3 '11 at 23:23 Using e.preventDefault(), jQuery does cancel the event for you. What do you mean by have jQuery cancel the event instead of me?

Edit: It doesn't cancel the event; the code inside the handler still executes, it just stops the default behaviour of the event. – JamWaffles Dec 3 '11 at 23:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions