0

I currently have a $.getJSON call which is working fine as shown below.

var jsonUrl = "http://www.somesite.co.uk/jsonusv.php?callback=?";                   
$.getJSON(jsonUrl,function(zippy){
...some code
}

However, I wish to pass a variable with it so that the PHP script can use its $_GET[''] value and tailor the data.

I tired the fooling but could not get things to work any ideas ?

var jsonUrl = "http://www.somesite.co.uk/jsonusv.php?callback=?&value=65";

The php page looks something like this this had been stripped down. I did try to detect the $_GET['value'] but it didn't work.

<?PHP
header("content-type: application/json");  
$theSqlquery = "SELECT * FROM table ORDER BY timestamp DESC LIMIT 20";   
$result131 = mysql_query($theSqlquery);

     if ($result131)
     {

        //make up Json string in $temp

    echo $_GET['callback'] . '(' . $temp . ');';
     }                 
?>
4
  • Hi Behnam Esmaili i don't understand your question Commented Nov 29, 2012 at 19:30
  • i have posted an answer.check. Commented Nov 29, 2012 at 19:31
  • Have you tried using a different name for "value" ... your jQuery/JS code works just fine. However, maybe there's a problem with using "value" as the name of a key (in PHP)? Commented Nov 29, 2012 at 19:50
  • possiblty this can help you stackoverflow.com/questions/6555172/… Commented Aug 8, 2013 at 11:55

3 Answers 3

1

I would suggest removing the callback=? from your jsonUrl

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

1 Comment

a url querystring starts with a ? If you're checking the 'callback' property and want to pass an empty value just leave ?callback=&value=65". I would imagine you're querystring is kind of jacked up with the question mark in the middle of it.
0

Try passing your parameters into the data parameter of the function call instead of query string:

var jsonUrl = "http://www.somesite.co.uk/jsonusv.php";
$.getJSON(jsonUrl, {
    callback: "your callback val",
    value: "65",
  },
function(zippy){
...some code
});

http://api.jquery.com/jQuery.getJSON/

Then you can access them with $_POST

Note, echo sends the supposed json result back to your $.getJSON() method call, e.g., success() if it was successful. If you know the js method name in the success() method, and only need to pass it $temp, try this

var jsonUrl = "http://www.somesite.co.uk/jsonusv.php";
$.getJSON(jsonUrl, {
    value: "65"
  },
function(zippy){
    callbackMethod(zippy[0]);
});

and in your php

$output = array();
$output[0] = $temp;
echo json_encode($output);

3 Comments

but he wanna access it with $_GET.
I am ok with POST but your method with no callback=? in the URL causes an Access-Control-Allow-Origin.
Also its still GET not post.
0
var jsonUrl = "http://www.somesite.co.uk/jsonusv.php?callback=?";                   
$.getJSON(jsonUrl,{lastdatetime: "",},function(zippy){....

Seems to work ...

Comments

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.