Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass null value using ajax to PHP?

Tags:

ajax

php

I am new to AJAX and PHP. i want to Replace the Variable value to null.

index.php

<script type="text/javascript" src="javascripts.js"> </script>

<input type="submit" value="Set Value" onclick="makeRequest('index.php?testvalue=7',   'get', null); "/> 
<input type="submit" value="Unset Value 1" onclick="makeRequest('index.php?testvalue=null', 'get', null); "/> 


<h1><?php echo "PHP Test Value: " .  $_GET['testvalue']; ?></h1>

Im trying to change the value of $_GET['testvalue'] to null whenever I hit the Unset Value button but what is happening is that it doesn't change the $_GET['testvalue'] variable to null but instead of it does something like $_GET['testvalue'] = 'null'; It appears to me that it passes null as a string.

like image 416
Moron Avatar asked Aug 27 '11 10:08

Moron


1 Answers

Only strings can pass from a form request. You could instead pass an empty string and interpret that as null.

like image 119
Madara's Ghost Avatar answered Nov 10 '22 15:11

Madara's Ghost