AJAX to PHP发送值

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

Never mind. Turns out this works

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

This should work better:

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

Try this:

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

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