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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)