Unable to get JQuery to return AJAX data
I'm relatively new to JQuery, so before I try to build the actual app, I'm trying to build a simple Ajax script that'll simply return the data.
However, despite more or less copying and pasting the code, I still can't get it to work.
<html>
<head>
<title>This is a title!</title>
<script src="scripts/jquery-1.4.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function(){
alert ('1');
$.ajax({
url: 'process.php',
dataType: "html",
success: function(data) {
$('#testsite').html(data);
alert('Load was performed.');
}
});
alert ('2');
});
</script>
</head>
<body>
<div id='login'>
<div id='testsite'>
</div>
<input type='button' id='lsubmit' value='Submit' /开发者_如何学Python>
</div>
</body>
</html>
The JQuery script is definitely loaded, process.php is definitely called up (it creates a text file just to prove that it has in fact been run) but anything echo'd in the process.php doesn't get sent through as data.
It's probably something simple, but I've run out of ideas.
Thanks in advance
Okay, this was major stupidity on my part. I messed up the process.php file so it didn't have any data to return
I have no memory of doing this and no idea why I did. Sorry for wasting your time and thanks to all those that helped =]
You will want to add an error handler, see if that gets fired, and inspect the error that is happening.... Add a callback to error.
HTH.
Try using these
$.get('ajax/test.html', function(data) { $('.result').html(data); alert('Load was performed.'); });
$.post('ajax/test.html', function(data) { $('.result').html(data); });
even you solve yur problem , you can try these
精彩评论