使用$ .getJSON我的链接包含%0A +++++个字符

时间:2012-05-26 15:23:43

标签: asp.net-mvc-3 jquery

我尝试从所选行中获取值,并将它们作为参数传递给$ .getJSON。我可以获得该值,但是,当我点击链接时,值前后出现奇怪的字符。链接中的字符显示为%OA ++++++++++++++++++++++++++++++++++++

这是我的代码

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');
    });
链接中的

部分显示正常,唯一的问题是类名

更新

小提琴链接 http://jsfiddle.net/gordon/vzTDc/2/

1 个答案:

答案 0 :(得分:1)

试试这个。我觉得现在好了。

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);
    });
});

<强> DEMO