Tôi phải chuyển biến mảng Javascript sang PHP,
vì vậy tôi không thể chuyển biến mảng từ javascript sang php
Vì vậy, dưới đây là mã tôi đã cố gắng
Những gì tôi đã thử
CSV File to HTML Table Using AJAX jQuery$[ document ].ready[function[] { $[ ".button1" ].click[function[] { var val = []; $["input:checked"].each[function [index,value] { val[index] = this.value; }]; var myJSONText = JSON.stringify[val]; $.ajax[{ data: {'kvcArray': myJSONText}, url: 'Index.php', type: 'POST', success: function[data] { alert[data]; } }]; }]; }]; console.log['Debug Objects: " . json_decode[$_POST['kvcArray'], true] . "' ];"; var_dump[json_decode[$_POST['kvcArray'], true]]; die[]; } ?> $[document].ready[function[]{ $['#load_data'].click[function[]{ $.ajax[{ url:"FILES/employee.csv", dataType:"text", success:function[data] { var employee_data = data.split[/\r?\n|\r/]; var table_data = 'Manage Instances
Load Data
Existing Members |
...or Join usDownload, Vote, Comment, Publish. |
||
|
When answering a question please:
- Read the question carefully.
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
- If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
- Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
This content, along with any associated source code and files, is licensed under The Code Project Open License [CPOL]
CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 [416] 849-8900
Làm cách nào để chuyển mảng từ PHP sang AJAX?
Để gửi mảng PHP dưới dạng phản hồi của yêu cầu AJAX, trước tiên bạn cần mã hóa mảng đó bằng hàm json_encode[]. .
$a = [“chuỗi1”,”chuỗi2”];
tiếng vang json_encode[$a];
Làm cách nào để chuyển một mảng trong AJAX?
Bạn có thể chỉ cần chuyển một biến Mảng JavaScript trong $. ajax như bất kỳ biến nào khác . Trên tập lệnh PHP, bạn có thể trực tiếp sử dụng nó như một Mảng PHP bình thường.
Làm cách nào để chuyển mảng trong AJAX sang bộ điều khiển?
Giải pháp 1
. "ĐĂNG", url. "/ExcelImport/SaveMappings", dữ liệu. { ánh xạ cột. cộtMappings }, kiểu dữ liệu. "json", thành công. chức năng [] { cảnh báo ["Ánh xạ thành công"] }, thất bại. function [] { alert["không hoạt động. "]; } }];
Làm cách nào để chuyển mảng sang PHP?
Phương pháp 1. Sử dụng hàm json_encode[] . Hàm json_encode[] được sử dụng để trả về biểu diễn JSON của một giá trị hoặc mảng. Hàm có thể lấy cả mảng một chiều và nhiều chiều.