Asp.net mvc 3 使用$.getJSON,我的链接包含%0A+++++;人物
我试图从所选行获取值,并将它们作为参数通过$.getJSON传递。我可以得到这个值,但是,当我点击链接时,奇怪的字符出现在这个值的前后。链接中的字符显示为%OA+++value+++0A 这是我的密码Asp.net mvc 3 使用$.getJSON,我的链接包含%0A+++++;人物,asp.net-mvc-3,jquery,Asp.net Mvc 3,Jquery,我试图从所选行获取值,并将它们作为参数通过$.getJSON传递。我可以得到这个值,但是,当我点击链接时,奇怪的字符出现在这个值的前后。链接中的字符显示为%OA+++value+++0A 这是我的密码 var className=''; var Section=''; $('#listsubject tr').click(function () { var th = $(this); var td = $(this).find('td');
var className='';
var Section='';
$('#listsubject tr').click(function () {
var th = $(this);
var td = $(this).find('td');
$.each(td, function (index, item) {
if (index == 2) className = item.innerHTML;
});
$.getJSON('@Url.Action("getStudentList/","Student")',
{ classname: className
}, function (data) {
alert('test');
});
请帮帮我。我被困在这里
提前谢谢
编辑
当我尝试代码时
$.getJSON('@Url.Action("getStudentList/","Student")',
{ classname: className,
section:'A'
}, function (data) {
alert('test');
});
在链接中,部分显示的很好,唯一的问题是类名
更新
小提琴连杆
试试这个。我想现在可以了
var className = '',
Section = '';
// you were trying with $('#listsubject tr'), but first tr has no td
// so click should bind with tr from 2nd
// so correct selector will be $('#listsubject tr:gt(0)')
$('#listsubject tr:gt(0)').click(function() {
var th = $(this);
var td = $(this).find('td');
$.each(td, function(index, item) {
// As you have 2 td with in each row, so the index will be 0 and 1
// not 2 and 3
if (index == 0) {
className = $.trim($(item).text()); // $.trim() will remove spaces
}
if (index == 1) {
Section = $.trim($(item).text());
}
});
console.log('ClassName: ' + className + ', Section: ' + Section);
$.getJSON('StudentMarks/getSubjectGrading', {
classname: className,
section: Section
}, function(data) {
alert(data);
});
});
$(item.html();返回null,而$(item).text()为空;返回blank当我使用alert(className)时,它显示正确的值。那么,额外的字符是否使用$.getJSON显示在链接中?当使用.text或.html时,它显示为未定义的。我很抱歉,它仍然显示相同的字符(%0A+++)这%0A+++在链接中到底意味着什么?@Gordon除非你做了一个小提琴或发布了你的标记,否则就不可能再进一步了step@thecodeparadox对不起,我没有用小提琴:(@Gordon——他的意思是访问以创建问题的演示。JSFiddle.net是一个网站,您可以在其中发布JS/CSS/HTML代码以进行实验,并查看其在受控环境中的工作情况。这对调试非常有用,也可以向人们展示问题所在。@Spudley感谢您的建议……我现在是JSFiddle的忠实粉丝;)