This question already has answers here:
Closed 7 years ago.
Possible Duplicate:
how to get GET and POST variables with JQuery?我有以下HTML:
<form action='.' method='post'>{% csrf_token %} <div class="parameters"> Show <select name="earnings_filter"> <option value="all">Total earnings</option> <option value="hd">HD earnings</option> <option value="sd">SD earnings</option> </select> <input type="submit" name="submit" class="submit float-right" value="submit" id="submit_financials"/> </div> </form>
我需要对此进行ajax调用:
$("#submit_financials").live('click', function(){ ... });
有没有一种方法可以获取在POST中提交的变量,例如选择了哪个选项(我还需要获取大约10个其他变量)。还是我需要使用jQuery选择器来获取每个选择器的值?
参考方案
$("#submit_financials").live('click', function(){ $.ajax({ url: '', // script url to send method: 'POST', // method of sending data: $('form').has(this).serialize(), // .serialize() make query string with form inputs name and value dataType:'json', // expected data format returned from server, you may have something else success: function(response) { // response contains data returned from server } }); });
如果您使用的是jQuery> 1.7,最好将
live()
替换为.on()
,并且如果可能的话会更好。所以你可以写$("#container").on('click', '#submit_financials', function(){ $.ajax({ url: '', // script url to send method: 'POST', // method of sending data: $('form').has(this).serialize(), // .serialize() make query string with form inputs name and value dataType:'json', // expected data format returned from server, you may have something else success: function(response) { // response contains data returned from server } }); });
这里的
打印二维阵列 - javascript#container
指向页面加载时属于DOM的#submit_financials
的持有者。我正在尝试打印子元素。在this example之后。怎么做?。$myarray = array("DO"=>array('IDEAS','BRANDS','CREATIVE','CAMPAIGNS'), "JOCKEY"=>a…
如何调用超链接单击中包含单引号的消息的JavaScript警报? - javascript我陷入了javascript问题。我正在使用C#编写可以调用javascript来显示警报消息的超链接。请参阅下面的代码以了解它是如何完成的:首先,这是C#从服务器端编写的代码://Server side code string myHyperlink = "<a href='#' onclick=\"alert…
如果我得到url(''),我该如何使用另一个URL - javascript我是新手,正在写这篇文章,但是如果源上没有图像,那么我只有空白。有人可以告诉我,如果我正在获取背景图像,如何获取/images/no-image.jpg:url();这是我的代码:<div class="uk-clearfix uk-position-relative"> <div class="recipeb…
点击ID的身份 - javascript我正在使用php codeigniter。我正在将数据发送到我的视图中。在我看来,我有一个foreach循环,该循环遍历数组并在我的视图中显示数据。同样在此foreach循环中,我正在显示一些操作按钮。 <?php foreach($studentList as $r) { echo '<tr>'; echo $r-&g…
javascript popupwindow之后的行如何工作? - javascript好的,我有一个来自后面代码的方法,可以创建一个popupwindow。然后有一行代码要在那之后执行,我想知道那行代码何时执行,是在使用popupwindow之后执行还是在创建popupwindow之后执行?例如:void exPopupWindowMethod() { string scr = "window.open('exampleP…