'TinyMCE4 `image_list` external url
I am trying to get TinyMCE 4's image_list
to work with a URL returning JSON data as specified in the example here.
I have setup a GET
endpoint http://demo.com/media
on my server which gives back a JSON response consisting of a list of objects with their title
and value
attributes set, for example:
[{"title":"demo.jpg","value":"http://demo.com/demo.jpg"}]
I have also specified the option image_list: "http://demo.com/media"
when initializing the plugin.
However, when I click the image icon in the toolbar, nothing pops up. All I can see in the network tab is an OPTIONS
request with status 200, but then nothing. The GET
request I was expecting never happens.
What is the correct way of using image_list
in TinyMCE 4? Also, does anyone have a working demo example? I couldn't find anything.
Solution 1:[1]
It is somewhat hard to say what the issue is without seeing the exact data your URL is returning. I have created a TinyMCE Fiddle to show (in general) how this is supposed to work:
http://fiddle.tinymce.com/pwgaab
There is a JavaScript variable at the top (pretendFetchedData
) that simulates what you would grab from the server (an array of JavaScript objects) and that is referenced via image_list
.
If you enter your URL (http://demo.com/media
) into a browser window what is returned? Are you sure its an array of JavaScript objects?
Solution 2:[2]
I have the identical problem. No matter what I do with the detail of the format (e.g. putting quotes round title and value), nothing happens.
I guess the only way (for me anyway) is to insert the list into the script with php before sending the web page.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Michael Fromin |
Solution 2 | SJK |