2

Im starting off easy, but cant work out why this doesnt work.

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
><script>
$(document).ready(function(){
$("button").click(function(){

// $("#div1").load("details.php?date_1=31%2F1%2F1975&date_2=31%2F1%2F1985&submit=Submit" );

// $("#div1").load("details.php", {date_1:"31/1/1975", date_2:"31/1/1985"} );
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>

The 2 lines commented out, the first works, the second doesnt... I cant work out why?! Or how to make the second one work... Anyone?!

hjpotter92
  • 78,589
  • 36
  • 144
  • 183

2 Answers2

4

Take a look at the manual for .load: http://api.jquery.com/load/

The POST method is used if data is provided as an object; otherwise, GET is assumed.

Your 2nd line uses POST whereas the 1st uses GET, this is probably why one works and the other does not.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
-1

If you must use load - take one of the other answers, otherwise - this keeps your format:

$.post('details.php', {date_1:"31/1/1975", date_2:"31/1/1985"}, function(data) {       
    $("#div1").html(data);
});
mikevoermans
  • 3,967
  • 22
  • 27
  • The issue was that he didn't realize that `.load` was using POST. His `details.php` file probably uses GET, so you should use `$.get`. – gen_Eric Mar 12 '13 at 13:48