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 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
  • ¥50 C++五子棋AI程序编写
  • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
  • ¥15 SQL Server analysis services 服务安装失败
  • ¥15 基于面向对象的图书馆借阅管理系统
  • ¥15 opencv图像处理,需要四个处理结果图