我是jQuery的新手,需要帮助弄清楚$.get为什么不回复。
让我解释一下我有什么:有一个主要的index.php如下:
<!DOCTYPE html>
<html lang="en">
<head> <meta charset="utf-8"> </head>
<body>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/reqhan.js"> </script>
<input id="string" type="text" />
<input id="button" type= "button" value="Go" />
<div id="div"></div>
</body>
</html>
js/reqhan.js包含
$(document).ready(function(e) {
alert('1');
$('#button').click(function() {
$.get('php/reverse.php',{input: string},function(data){alert('2');});
$('#div').text(data);
alert('3');
});
});
reverse.php包含一个简单的代码(我粘贴在这里,但没有预览它),它从reqhan.js文件中获取文本并返回一条echo消息。
当在Google Chrome上运行代码时,会显示第一个警报,但不会显示其余警报,当然还有`$('#div').text(data);'不会将数据发送回js文件。
如果需要进一步的信息,请告诉我。非常感谢。
在对数据进行任何操作之前,您将关闭回调函数
试试这个:
$(document).ready(function(e) {
alert('1');
$('#button').click(function() {
$.get('php/reverse.php',{input: string},function(data){
alert('2');
$('#div').text(data);
alert('3');
});
});
});
尝试格式化代码,使每对括号都有自己的缩进。它应该有助于捕捉这样的小事。