0

On the front-side i am recording user selections:

 var type = $.cookie('liste-voyage-type');  
 var code=  $.cookie('liste-voyage-code');  

i then pass these variables to the server

$.ajax({
   url: '../listing-voyage-produit.php', 
   type: "GET",     
   data :  ({type: type,code :code}),
  success: function(data){
         alert('data:'+data);
  }
}); 

i want to dynamically modify the variables

  $type and $code 

at the back end which are used for a sql request that display products on the page

i miss some elements of understanding:

  alert('type:'+type);    => type:2

  alert('code'+code);    => code:Z3\_P95\_

  the success: alert('data:'+data);    =>  data:

the callback function is triggered but the alert(data) does not display anything

how can i play with datatype, json, or eval() to make it working , converting the string variales var type and code to json and ultimately modify the variables on the server side to :

  echo $type;

  echo $code;
6
  • 2
    if you are not retrieving any data in success, you wont be able to see any data... make sure your success callback return some data... Commented Dec 13, 2013 at 11:39
  • 2
    Have you used Fiddler to check the response body? Commented Dec 13, 2013 at 11:40
  • what about server side code? What did you do there to get the result? Commented Dec 13, 2013 at 11:42
  • 1
    in this function function(data){ data will be the response from server side listing-voyage-produit.php. Commented Dec 13, 2013 at 11:43
  • does the javascript give you an error upon .get() request and what exactly are you trying to do with the backend? Commented Dec 13, 2013 at 11:45

2 Answers 2

2

your code missing dataType

$.ajax({
   url: '../listing-voyage-produit.php', 
   type: "GET",     
   data :  {type:type,code:code},
   dataType:"json",
  success: function(data){
         alert('data:'+data);
  }
}); 
Sign up to request clarification or add additional context in comments.

Comments

1

Do not wrap your data with parenthesis ()

JAVASCRIPT

...
data :  {type: type,code :code},
dataType: 'json',
...

PHP

// decode data sent
$json = json_decode($_POST['data']);

// encode data to send back
echo json_encode($json);

2 Comments

this won't solve OP issue but that's right than here parenthesis are useless (but still valid)
what are you trying to do exactly? pass the data to a php file and return the same exact data back?

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.