Frage

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

War es hilfreich?

Lösung

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.

Andere Tipps

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);
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top