Question

I am attempting to use variables as the key/value parameters during my getJson call. I can put in the actual values and it works but when I attempt to plug in the variables, nothing is returned. I am not sure of the exact syntax that I should use for plugging in the variables. The variables are order and store. Any help will be really appreciated.

  var order = <?php echo $orderid; ?>;
  var store = <?php echo $store; ?>;

  function ajaxCall(){

findPrinter();


 $.getJSON('http://www.webaddress.com/printlabels/qz-print/dist/api2.php?', {
    order:  "order", 
    store:  "store" 
 },function(data){
Was it helpful?

Solution 2

Change the code like @Abimbola says, and in case that the $orderId and the $store be strings, change:

var order = <?php echo $orderid; ?>;
var store = <?php echo $store; ?>;

To this:

var order = "'" + <?php echo $orderid; ?> + "'";
var store = "'" + <?php echo $store; ?> + "'";

OTHER TIPS

Change { order: "order", store: "store" } to { order: order, store: store }.

I usually take the extra step and write it as { "order": order, "store": store }. That way it is more clear what is going on. The " strings are constant values, while the non-quoted words are variable names. But when you have the word to the left of :, it is a constant anyway regardless of whether you use ".

If you need further help, please clarify your question.

Change this:

$.getJSON('http://www.webaddress.com/printlabels/qz-print/dist/api2.php?', {
    order:  "order", 
    store:  "store" 
},function(data){

...to this:

$.getJSON('http://www.webaddress.com/printlabels/qz-print/dist/api2.php?', {
    "order":  order, 
    "store":  store 
},function(data){

In javascript, it is the key that is String, the value can be another other valid javascript primitive, object or function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top