7

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.

1 Answer 1

10

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

Sign up to request clarification or add additional context in comments.

2 Comments

You mean I shud do something like makeRequest("index.php?testvalue=''", "get", null) ?
Almost, makeRequest("index.php?testvalue=", "get", null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.