Been trying to figure this out for hours...
I am attempting to use AJAX by grabbing values from a jQuery slider I have contained in an <input>
tag. AJAX does not fail (see code), and when I console.log
the variable I am trying to send through Data:
, it prints out correctly.
note: The jQuery and php are on the same page, so no url:
parameter, or whatever you will call it is used.
Here is the <script>
portion:
jQuery(function($){
$("input[id='protein-slider']").ready(function(){
var p_range;
var request;
$("input[id='protein-slider']").each(function () {
p_range = $(this).val();
});
console.log(p_range) //Returns correct values
request = $.ajax({
type: "POST",
data: p_range,
});
request.done(function (response, textStatus, jqXHR){
console.log("Hooray, it worked!"); //This prints, no error
});
request.fail(function (jqXHR, textStatus, errorThrown){
console.error(
"The following error occurred: "+
textStatus, errorThrown
);
});
});
});
and the <?php ?>
code in correlation with this function is:
echo $_SERVER['QUERY_STRING']; //returns nothing
$income_data = $_GET['p_range'];
echo $income_data; //returns nothing
var_dump($income_data); //returns "NULL"
I've lost track of all of the other methods I have done and the other countless awnsers I have read on here. None seem to work and it's getting quite depressing...
Hopefully one of you guys can spot something that I am doing stupid...
Thanks!