Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách lấy tập dữ liệu key/value từ form HTML


Để lấy tập dữ liệu key/value từ form HTML, dùng jQuery.

Giả sử HTML sau −

<form id = "form1">    <input type = "text" name = "demo" /> </form>

Cho JS −

var data = $('form#form1’).serializeArray(); // [{'demo: 'value'}] $.ajax({    data: data });