2
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Vì vậy, tôi đã viết một chương trình bằng JavaScript xuất ra JSON. Những gì tôi muốn làm là, với một nút bấm, tôi muốn chuyển trong JSON đó như một đối số cho một tập lệnh Python.
Tôi không hoàn toàn chắc chắn làm thế nào để tiến hành điều này:
$.ajax[{
url: "/path/to/your/scriptPython",
success: function[response] {
// here you do whatever you want with the response variable
}
}];
Bất kỳ phản hồi hoặc trợ giúp được đánh giá cao.
Được hỏi ngày 30 tháng 9 năm 2016 lúc 18:25Sep 30, 2016 at 18:25
3
Điều này phụ thuộc vào một cân nhắc quan trọng: Mã Python của bạn ở đâu?
Nếu bạn muốn Python chạy trên máy của người dùng, điều đó trở nên phức tạp do các biện pháp bảo mật: Các trang web thường không được phép thực thi mã tùy ý trên máy của người xem. [Hãy tưởng tượng nếu mã Python đó xóa ổ cứng của họ, ví dụ: trong trường hợp này, tốt nhất là người dùng sẽ tải JSON dưới dạng tệp và sau đó mở nó bằng chương trình Python của bạn.
Nếu bạn muốn Python chạy trên máy chủ của mình, bạn có thể thực hiện yêu cầu bài đăng đến điểm cuối của tập lệnh và chuyển JSON trong dữ liệu bài đăng. Các chi tiết về điều này sẽ phụ thuộc vào sự lựa chọn của bạn về khung web Python [tôi thích bình], nhưng JavaScript sẽ khá giống nhau:
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
Đã trả lời ngày 30 tháng 9 năm 2016 lúc 18:44Sep 30, 2016 at 18:44
DraconisdraconisDraconis
3.0291 Huy hiệu vàng15 Huy hiệu bạc27 Huy hiệu đồng1 gold badge15 silver badges27 bronze badges
1
import
random
def
output[compliments]:
print
[random.choice[
tuple
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
0def
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
2
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
4$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
5 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
6$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7import
1$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7import
4$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7import
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7random
0$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7random
3$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7random
6$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7random
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7def
2$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7def
5$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7def
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7output[compliments]:
1$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7output[compliments]:
4$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7output[compliments]:
7 output[compliments]:
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7output[compliments]:
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9
4
6
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
5 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
6$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7print
0print
1 print
2$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7print
4print
1 print
6$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7print
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7[random.choice[
0$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7[random.choice[
3$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7[random.choice[
6$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7[random.choice[
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7tuple
0$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7tuple
2print
1 tuple
4$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7tuple
6$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7tuple
8$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
9$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
01$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
03$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
05$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
06 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
07$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
09$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
10 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
11$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
12 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
13$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
15$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
17$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
18$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
19$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
21$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
22 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
23$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
25$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
27$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
06 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
29$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
31$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
33$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
06 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
35$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
37$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
39$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
40$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
41$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
43$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
45 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
46$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
48$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
50print
1 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
52$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
54$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
56$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
58$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
59$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
60$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
06 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
62$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
64
4
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
68 $.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
69$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
71
$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
73$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
74$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
7$.ajax[{
type: 'POST',
data: my_json_variable,
url: '//example.com/python_endpoint',
success: function[response]{ /* deal with the script's output */ }
}];
76