我有以下jQuery文件。我尽力找到问题所在。但是,我做不到。我是新手。请帮忙。提前致谢。
在此输入您的文字。
<p id="result"></p>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#count").on("click",function(){
var strings = $("#textarea").val();
if(strings=="")
{
$("#result").text("Please put some text to count words");
}
else
{
$.ajax({
type:"POST",
url:"countwords.php",
data:{strings:'strings"};
}).done(function(){
$("#result").html(msg);
});
}
});
$("#clear").on("click",function(){
$("#textarea").val("");
});
});
</script>
答案 0 :(得分:3)
尝试在此更改data
值:
data:{strings:'strings"};
为:
data: {strings:strings} // ; no semi-colon here either
并且您还缺少msg
函数的done
参数,应该是:
.done(function(msg){
------------- ^ here ----
$("#result").html(msg);
});
答案 1 :(得分:2)
将此代码替换为
<p>Enter your texts here.</p>
<textarea id="textarea" placeholder="Put Your Text here to Count Your words."></textarea>
<input type="reset" value="Clear" id="clear"/ >
<input type="submit" value="Count" id="count"/ >
<p id="result"></p>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#count").on("click",function(){
var strings = $("#textarea").val();
if(strings=="")
{
$("#result").text("Please put some text to count words");
}
else
{
$.ajax({
type:"POST",
url:"countwords.php",
data:{strings:strings}
//You missed msg arguement
}).done(function(msg){
//alert(msg);
$("#result").html(msg);
});
}
});
$("#clear").on("click",function(){
$("#textarea").val("");
});
});
</script>