如何使用jQuery的ajax数组发布JSON?

编程入门 行业动态 更新时间:2024-10-27 10:34:43
本文介绍了如何使用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?

本文发布于:2023-10-12 02:55:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   如何使用   ajax   jQuery   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!