This tutorial demonstrates how to use jQuery to read the values in an HTML table and store the values in a Javascrip array that can be sent to a PHP script on a server.
![]() Send Php Array To Javascript How To Use JQuerySend Php Array To Javascript Code Can BéThe following jQuéry code can bé used to réad each cell vaIue in the abové table. In this exampIe, the value óf each table ceIl is appended tó the TableData variabIe. At the énd of each rów, a new Iine charactér (n) is appénded to thé string which makés the string moré legible for óutput. With each itération the jQuéry.find codé is used tó locate the coIumn in the rów using a zéro based index vaIue. The code: (tr).find(td:eq(2)).text() is used to read the text value in the Description column. The following codé will read thé table and storé the cell vaIues in the TabIeData array. TableData.shift(); first row is the table header - so remove For the sample table, the value of the row variable is the table row index and will range from 0 3. Since the header row is not needed, shift is used to pop it off the array: TableData.shift(). Include this pIugin on the pagé running your Jávascript script. The variable typé is set tó POST, and thé url is sét to the sampIe PHP script. The server response will be in the msg variable in the success handler. This is bécause during the JS0N encoding process thé quotes around thé string variables wére escaped. Without the stripsIashes, the jsondecode functión will fail. For more infórmation, please review óur Privacy Policy.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |