Moron
Moron

Reputation: 697

How to pass null value using ajax to 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.

Upvotes: 7

Views: 6316

Answers (1)

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 175088

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

Upvotes: 10

Related Questions