【发布时间】:2012-10-12 18:48:12
【问题描述】:
我有一个下载按钮,点击后应该会更改元素跨度的文本,但我在 ajax 部分有问题
点击后会显示一个小按钮,文字不会改变
这是我的html
//somecode
<span class="num">Downloaded:<?php echo $downloadcount;?></span>
</td></tr>
</table>
</div>
<button type = "button" class="button" id="<?php echo $id; ?>" name="dl">
<a href='./mp3/<?php echo basename($filename);?>'>Download</a>
</button>
</td>
</tr>
</table>
这是我的 ajax:
$(function() {
$(".button").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if(name=='dl')
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "download_number.php",
data: dataString,
cache: false,
success: function(html)
{
//THE PROBLEM IS HERE
$(".num").text(html);
} });
}
});
});
我也试过$(".num").html(html);
【问题讨论】:
-
点击后会显示一个小按钮,文字不会改变
-
执行 alert(html) 或 console.log(html) 会得到什么?
-
它没有显示我现在尝试的警报框
-
download_number.php文件中有什么内容? -
@nikparsa:那么
success回调没有运行。试试error而不是success。