order = $('#userInput').val();
var data = '".CJSON::encode($model->getOrder('12345')."';
d = JSON.parse(data);
other code to add user feedback will go here
I would like this to be an AJAX call to somehow read the user input from userInput and use the $model->getOrder() method to retrieve a customer po number (along witho other data from the database and use this information in my JQuery to provide feedback to the user (ie: adding a row to a table showing the selected data).
Any ideas why I cannot escape the string and use the order variable in my method? Is there another way to do this?
Thank you Keith and bennouna for a quick response. Well, the missing parenthesis was a typo, and I tried removing the quotes but that did not work. When I manually use an order number in the function, it works fine - I just cannot use the variable.
var data = '".CJSON::encode($model->getOrder('123456'))."';
These do not:
var data = '".CJSON::encode($model->getOrder('"+order.toString()+"'))."';
var data = '".CJSON::encode($model->getOrder("+order+"))."';
As you can see, I event tried casting the variable to a string, just in case. Any other ideas?
You can achieve the result you want through Ajax (you pass your order variable to a simple action that echoes back the JSON array).
PS Oh I see you’re already talking about an Ajax call in your first post. I’m confused, where’s the Ajax call?
The goal is that a user can dynamically add order information to a table by inputting an order number. This will call up a function to query my database, get some additional data, and generate the new populated row.
Is there an example of a script somewhere that does something similar so I can have a looks at it?
Any advise would be greatly appreciated. Thank in advance!