I am trying to give a jQuery variable to a PHP variable when document is ready. What I have is a list with all sort of values with different links, which I get by an external website via cURL. With jQuery I am getting the value's by the href link. So what I want is when document is ready with loading, then it should give the jQuery variable to a php variable and echo it.
What I have so far:
//Javascript.js
$(document).ready(function() {
var value = $("a[href='index.php?p=trading&m=42&b=BTC']:eq(3)").text();
$.ajax({
url: "index.php",
type: "get",
data: value,
success: function(){
alert("success");
alert(value);
},
error:function(){
alert("failure");
}
});
alert(value);
});
The output of value = 55.0
<a href="index.php?p=trading&m=42&b=BTC">55.0</a> //from cURL page
<!-- index.php -->
<?php
$a = $_GET['value'];
if($_GET['value'] == "")
{
echo("empty");
}
else {
echo($a);
}
?>
The GET/POST is success, but it doesn't show up at the php page. Hope anyone got a solution for this.
echobe? within the same page you are calling theajaxfunction?data: value,is what's being passed to the PHP file, you need a response object like the answer below which will hold what's returned from the PHP file