本文介绍了如何使用jQuery的ajax数组发布JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在ajax json帖子中发送数组,但是有些代码是错误的.如何计算此代码?
i want to send array in ajax json post ,but some code are error.how to fig this code?
HTML
<table width="200" border="1"> <tr> <td>table</td> <td> <input name="table[]" type="text" id="table[]" value="5" /> </td> </tr> <tr> <td>menu</td> <td><input name="menu[]" type="text" id="menu[]" value="noodle" /></td> </tr> <tr> <td>number</td> <td><input name="number[]" type="text" id="number[]" value="1" /></td> </tr> <tr> <td>note</td> <td><input name="note[]" type="text" id="note[]" value="no " /></td> </tr> <tr> <td>table</td> <td><input name="table[]" type="text" id="table[]" value="1" /></td> </tr> <tr> <td>menu</td> <td><input name="menu[]" type="text" id="menu[]" value="beer" /></td> </tr> <tr> <td>number</td> <td><input name="number[]" type="text" id="number[]" value="2" /></td> </tr> <tr> <td>note</td> <td><input name="note[]" type="text" id="note[]" value="-" /></td> </tr> </table> <button id="save-menu">save</button> <button id="calculator">calculator</button>Jquery:如果我单击按钮保存菜单,它将向菜单/命令发送一些数据,或者单击按钮计算器,它将向菜单页面发送一些数据.但不是我的jQuery代码未将所有值都发送到数组中,如何计算此代码?请帮助我.谢谢.
Jquery : if I click button save-menu it send some data to menu/order or I click button calculator it send some data to calculator page. But not my jquery code not send all value in array ,how to fig this code? Help me please.Thank you.
<script> $(document).ready(function(){ $('#save-menu').click(function() { $.post('menu/order', { table : $('select#workplace-table').val(), 'mid[]' : $('input#order-mid').val(), 'number[]' : $('input#order-number').val(), 'note[]' : $('input#order-note').val(), }); $('#calculator').click(function() { $.post('menu/calculator, { table : $('select#workplace-table').val(), 'mid[]' : $('input#order-mid').val(), 'number[]' : $('input#order-number').val(), }); }); </script>推荐答案
将事件处理程序绑定到"click" JavaScript事件,或在元素上触发该事件.
Bind an event handler to the "click" JavaScript event, or trigger that event on an element.
$( "#save-menu" ).click(function() { //Handler for .click() called. $.post('menu/order',{...}); }); $( "#calculator" ).click(function() { //Handler for .click() called. $.post('menu/calculator',{...}); });更多推荐
如何使用jQuery的ajax数组发布JSON?
发布评论