0

Hello i am quite new to jQuery. I am trying to insert search results in to page without reloading it, but unsuccessful. Here is the code i am using:

$(document).ready(function(){
  $("a").click(function(event){
	  $.get( 
		 "search.php",
		 { query: "intel" },
		 function(data) {
			$('#content').html(data);
		 }
	  );
  });
});

i am using example form some page. I edited it but i lack the knowledge to make it work.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by mi.mac.rules
0

you need to add event.preventDefault(); to your onclick function to prevent your page from being redirected by the link you are clicking on
leaving out the href from the tag or having an empty href just tells the page to redirect to its self

$("a").click(function(event){
	  event.preventDefault();
	  $.get( 
		 "search.php",
		 { query: "intel" },
		 function(data) {
			$('#content').html(data);
		 }
	  );
  });
0

I agree with jstfsklh211, but event.preventDefault() has always crashed my javascript in IE.
So if you're worried about IE, I would do this:

$("a").click(function(event){
	  if(!$.browser.msie) { // if you're not in IE, do this
event.preventDefault();
}
	  $.get( 
		 "search.php",
		 { query: "intel" },
		 function(data) {
			$('#content').html(data);
		 }
	  );
  });

<a onclick="function(); return false;">...</a>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.