weixin_33726318 2015-07-01 06:59 采纳率: 0%
浏览 24

使用jquery和php的ajax

I have a input field with id age. I am trying to pass this age and some other values from other input fields using ajax as follows-

var age = document.getElementById('age').value;
var wpm = document.getElementById('wpm').value;
var sex = document.getElementById('sex').value;
var queryString = "?age=" + age ;

queryString +=  "&wpm=" + wpm + "&sex=" + sex;
ajaxRequest.open("GET", "ajax-example.php" + queryString, true);
ajaxRequest.send(null); 
ajaxRequest.open("GET", "ajax-example.php" + queryString, true);

so in my javascript part of my html document if i write

var age = document.getElementById('age').value;

the program executes perfectly.

But if i write this instead of the above statement -

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

My age value is not passed

So my question is what is the differnece between the statements

var age = document.getElementById('age').value;
var age =$('#age').val();
  • 写回答

1条回答 默认 最新

  • weixin_33737774 2015-07-01 07:04
    关注

    Javascript

     var age = document.getElementById('age').value;
    

    Jquery

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

    If $("#age").val() is not working then odds are that you don't have the libraries loaded for jquery at all

    http://code.jquery.com/jquery-latest.min.js
    

    Is for the latest jquery libraries. If you load that library into your page than all jquery scripts and functions should work which I'm fairly positive ajax is a jquery function so you'll want to do that

    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵