1. Go to this page and download the library: Download emc/xmlhttprequest-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new EMC\Bundle\XmlHttpRequestBundle\EMCXmlHttpRequestBundle(),
);
}
php
use EMC\XmlHttpRequestBundle\Annotation\XmlHttpRequest;
/**
* @Route("/ajax/", name="_ajax_call")
* @XmlHttpRequest(type="json") // You can add streaming=true to get the streaming mode
*/
public function ajaxAction()
{
/**
* Data result
* mixed
* The response will be "{code:0,data:{1:'My result',2:'My fancy bundle',5:'My reponse'}}"
*/
return array(
1 => 'My result',
2 => 'My fancy bundle',
5 => 'My reponse'
);
}
php
use EMC\XmlHttpRequestBundle\Annotation\XmlHttpRequest;
use EMC\XmlHttpRequestBundle\Event\StreamingProgress;
/**
* @Route("/ajax/", name="_ajax_call")
* @XmlHttpRequest(type="json", streaming=true)
*/
public function ajaxAction()
{
for($i=0; $i<5; $i++) {
$event = new StreamingProgress($i*20, 'Execution message info ' . ($i*20) . '% ...');
$this->get('event_dispatcher')->dispatch( 'emc.streaming.progress', $event);
sleep(1);
}
return array(
1 => 'My result',
2 => 'My fancy bundle',
5 => 'My reponse'
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.