Skip Navigation

[Resolved] Assign php variable or shortcode data to jQuery variable

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#922833

I am trying to Get php variable or toolset view data in jQuery variable via js editor. I have created a view and updated its data in json format and now its giving result like this:
[ {"id": "11020", "title": "Video View"} , {"id": "2473", "title": "VCA Firehouse Animal Hospital"} , {"id": "2471", "title": "Tender Touch Animal Hospital"} , {"id": "1543", "title": "Find your perfect property for your home"} , {"id": "1541", "title": "We find homes that fit you"} ]

I have created another view and called json data formated view in js editor like this but its not working.
var data = '<?php echo do_shortcode([wpv-view name="orgchart-view"]) ?>';
console.log(data);

Can you please help me to get view value in js variable.

#923272

Hello,

I assume you are going to run Views shortcode [wpv-view] in the javascript, you can not use PHP code in the javascript, I suggest you try this:
1) output the view's result in a specific HTML div tag
2) use javascript to get the content of above specific HTML div, for example Jquery html():
hidden link