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?!

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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);
});

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.