json传值问题
悠悠虾 2011-06-10 08:07:08 帮忙看一下代码:
<script type="text/javascript">
$(document).ready(function () {
$("#btnComment").click(function () {
var txtComment = $("#txtComment").val();
$.ajax({
type: "post",
url: "CsdnAddComment.aspx/AddComment",
data: " { 'comment':txtComment}",
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (message) {
alert(message);
}
});
});
});
</script>
我加粗的那句话,假如按照上面那么写的话txtComment这个值没法传到后台,但是假如我改成'txtComment'(加上引号)这样的话值就可以传过去,但这传的值肯定是txtComment,而不是我想要的txtComment变量的值。应该怎么写呢?