snipt

Ctrl+h for KB shortcuts

Text only

Angular Ajax post to PHP

1
2
3
4
5
$headers = apache_request_headers();
if (empty($headers['Content-Length'])) exit;

$input = file_get_contents('php://input');
$post_object = json_decode($input);
https://snipt.net/embed/025b58161eb18a6417782d4d290f23a4/
/raw/025b58161eb18a6417782d4d290f23a4/
025b58161eb18a6417782d4d290f23a4
text
Text only
6
2019-07-16T08:42:20
True
False
False
/api/public/snipt/146985/
angular-ajax-post-to-php
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>$headers = apache_request_headers(); </span><span id="L-2"><a name="L-2"></a>if (empty($headers[&#39;Content-Length&#39;])) exit; </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>$input = file_get_contents(&#39;php://input&#39;); </span><span id="L-5"><a name="L-5"></a>$post_object = json_decode($input); </span></pre></div> </td></tr></table>
angular, ionic
1
2
3
4
5
6
7
8
9
--- 
+++ 
@@ -1,2 +1,5 @@
+$headers = apache_request_headers();
+if (empty($headers['Content-Length'])) exit;
+
 $input = file_get_contents('php://input');
-$object = json_decode($input);
+$post_object = json_decode($input);
1
2
3
4
5
--- 
+++ 
@@ -0,0 +1,2 @@
+$input = file_get_contents('php://input');
+$object = json_decode($input);