I am using an HTML table and dynamically adding rows to it via Javascript. I am trying to pass the data from these rows to PHP / Laravel using input="hidden". Adding the rows to the HTML page seems to work fine, however I can't access the data when I call them from my PHP script. ($test doesn't seem to return anything) Any ideas why? Thanks!
HTML:
<table id='mytable'>
</table>
<input type='button' id='btnAddRow' value='Add' onclick='javaScript:addRow();'>
JS:
function addRow(){
var newRow = document.all("mytable").insertRow(-1);
var cell = newRow.insertCell(-1);
cell.innerHTML = "<input type='hidden' id='mydata' value='hello'>";
}
PHP:
$test = Input::get('mydata');
return $test;
它应该是name="mydata"
而不是id='mydata'
为了将数据从行动态传递到PHP,您需要进行xmlhttprequests(ajax)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.