问题描述:

var studno = $('#studno').val();

$(document).ready(function () {

$('.go').click(function () {

$('.inup').load('prochat.php', {

studno: studno

});

});

});

I have this code and it's supposed to send the value of studno into prochat.php but everytime it does it only says undefined. Can anyone explain?

网友答案:

Try this:

$(document).ready(function(){
    $('.go').click(function(){
        var studno = $('#studno').val();
        $('.inup').load('prochat.php', {studno:studno});
    });
});
网友答案:

Try this:

$(document).ready(function(){

    $('.go').click(function(){
        var studno = $('#studno').val();
        $('.inup').load('prochat.php', {studno:studno});
    });
});
网友答案:

Never mind. Turns out this works

$('.inup').load('prochat.php', {studno: $('#studno').val()});
网友答案:

These could be possible reasons:

  1. at the line where you are assigning the value to studno, the value of studno might be undefined
  2. #studno is not defined in the html

possible solutions:

-. try assigning the value within the click function:

like this:

$('.go').click(function(){
    studno = $('#studno').val();
    $('.inup').load('prochat.php', {studno:studno});
});

-. make sure that the element with id studno exists in the html document

网友答案:

This should work better:

$(document).ready(function () {
    $('.go').click(function () {
        $('.inup').load('prochat.php', {
            studno: $('#studno').val()
        });
    });
});
相关阅读:
Top