简体   繁体   English

将用户在 HTML 中输入的值传递给 jQuery.Ajax

[英]Pass value of user input in HTML to jQuery.Ajax

I want to pass a value from a user input in a html to jQuery.ajax .我想将 html 中用户输入的值传递给jQuery.ajax Here's the code for my JS file:这是我的 JS 文件的代码:

jQuery(document).ready(function() {
    jQuery.ajax({           
        type: 'POST',
        url: 'myurl.aspx',
        data: {
            action: 'something', 
            count: txtCount
        }
    });
});

and here's my html file:这是我的 html 文件:

Count: <input type="text" id="txtCount" name="count" />
<input id="btnSubmit" type="Submit" value="Submit" />
<div> output somewhere here</div>

My javascript is working, I just removed some of the codes since i'm just pointing out on how to pass the values from the html to my ajax.我的 javascript 正在工作,我只是删除了一些代码,因为我只是指出如何将值从 html 传递到我的 ajax。 I'm trying to develop a Chrome Packaged App.我正在尝试开发 Chrome 打包应用程序。

I guess you are looking for something like this:我猜你正在寻找这样的东西:

jQuery.ajax({           
    type: 'POST',
    url: 'myurl.aspx',
    data: {
        action: 'something', 
        count: $("#txtCount").val();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM