Search code examples
javascriptjsonajaxgetjsonofbiz

getJSON on a local JSON file


So I have a JSON file which contains some data, I've been trying to send a request from a JavaScript file using $.getJSON to retrieve that file but I'm unsure how to do so, is it possible to send a request directly to that file without having to setup request-map or view-map? If so where would store the file to make it publicly available.

I've tried using <@ofbisContentUrl> as it is stored in /images/[...]:

$.getJSON(
    '<@ofbizContentUrl>/images/[...]</@ofbizContentUrl>',
    function (data, text_status, jqXHR) {
        map.load_layer_data(data, [layer_file, layer_type]);
    }
).error(function (jqXHR, text_status, error_thrown) {
    busy.unset();

    /** Error reporting later... **/
    BootstrapDialog.show({
        type: BootstrapDialog.TYPE_DANGER,
        message: 'Failed to data for layer data.'
    });
});

This failed, so I then tried to setup a request-map/view-map but the again had no success,

<request-map uri="frs_get_mapping_points">
    <security https="false" auth="false"/>
    <response name="success" type="request" value="frs_json"></response>
</request-map>    

The documentation lacks any suitable information in regards to making a simple AJAX request to a local file hence I'm completely stuck. Any ideas how this can be achieved?


Solution

  • My JavaScript request was not parsing the Freemarker expression <@ofbisContentUrl> as a result it was not finding the file. What I had to do was in my .ftl file create a dummy variable with the location stores using <@ofbisContentUrl> and manipulate the string using .replace() to point it to the correct location.