2

How to detect if $_POST is set in Ajax calling PHP file and check it?

Is there any way I can see the Ajax Flow!

Right now I detect it like this:

if(isset($_POST['value']))

Updating value in DB or using Javascript Alert.

Dustin Kingen
  • 20,677
  • 7
  • 52
  • 92
  • 1
    What's the question? `isset($_POST['value'])` is how you check if a variable was `POST`ed or not. – gen_Eric May 29 '13 at 19:09
  • Use Chrome, press Ctrl-Shift-I, select network tab and inspect your ajax traffic with headers (Form Data == POST) – Imre L May 29 '13 at 19:16

1 Answers1

1

You could make in your PHP file like

echo" <p id='detect'>"; echo (isset($_POST['foo'])) ? $_POST['foo'] :''; echo "</p>"

Now, you could simply use Js, to detect if there is anything inside the <p> tag, using innHTML

var data = document.getElementById('detect').innerHTML;

if(data === ''){
 // means no post is made
}else{
 // post was made
}
samayo
  • 16,163
  • 12
  • 91
  • 106