简体   繁体   English

当它们不是来自HTML表单时,如何将PHP POST和FILES数据发送到AJAX URL调用?

[英]How do I send PHP POST and FILES data to an AJAX URL call when they are not from an HTML form?

I have a PHP page with $_POST and $_FILES data filled in. The POST data was obtained not from a traditional HTML form, but between multiple pages. 我有一个PHP页面, $_POST$_POST$_FILES数据$_FILES数据不是从传统的HTML表单获取的,而是在多个页面之间获取的。

For example, the POST data is a number of things: 例如,POST数据有很多东西:

$_POST["username"]
$_POST["password"]
$_FILES
etc.

The question is, how do I send this POST data off to an AJAX call within the page? 问题是,如何将此POST数据发送给页面内的AJAX调用?

I know with a form it's something like this: 我知道表格是这样的:

$.ajax({
   type: 'post',
   url: 'post.php',
   data: $('form').serialize(),
   success: function () {
     alert('form was submitted');
   }
 });

But what about directly from PHP's POST data? 但是直接从PHP的POST数据呢?

The question is, how do I send this POST data off to an AJAX call within the page? 问题是,如何将此POST数据发送给页面内的AJAX调用?

You can use WebSocket or EventSource and possibly ServiceWorker to stream data from server to client. 您可以使用WebSocketEventSource ,也可以使用ServiceWorker将数据从服务器流传输到客户端。 For example, see How to read and echo file size of uploaded file being written at server in real time without blocking at both server and client? 例如,请参阅如何实时读取和回显正在服务器上写入的上载文件的文件大小,而又不会阻塞服务器和客户端? where the requirement is to stream the progress of bytes of uploaded file being written to file at server by php in real time without blocking. 要求是实时传输由php实时将上传文件的字节进度写入服务器的文件,而不会阻塞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM