0

I am a newby in Magento, so sorry if my question seem stupid. I have an error

SyntaxError: JSON.parse: expected double-quoted property name at line 6 column 17 of the JSON data

that I don't understand, I mean I don't use JSON.parse and problem seems to come from this Magento core but I don't understant why. Here my .phtml :

    <input type='button' id='zip_btn' name='zip_btn'>  <style>   .hideme{display:none;} </style> <script type="text/x-magento-init">
            {
                "*": {
                    "Vendor_ZipCode/web/js/ajax": {
                        "AjaxUrl": "<?php echo $block->getAjaxUrl(); ?>",
                    }
                }
            } </script> <div id='test' class="hideme">
        <select>
          <% _.each(posts, function(text,value) { %>
             <option value="<%= value %>"><%= text %></option>
          <% }) %> 
         </select> </div>

and here js:

define([
    'jquery',
    'underscore',
    'mage/template',
    'jquery/list-filter'
    ], function (
        $,
        _,
        template
    ) {
        function main(config, element) {
            var $element = $(element);
            var zipurl = config.AjaxUrl;
            console.log('test');
            $(document).on('click','#zip_btn',function() {
                    var param = 'ajax=1';
                        $.ajax({
                            showLoader: true,
                            url: zipurl,
                            data: param,
                            type: "POST",
                            dataType: 'json'
                        }).done(function (data) {
                            $('#test').removeClass('hideme');
                            var html = template('#test', {posts:data}); 
                            $('#test').html(html);
                        });
                });
        };
    console.log('test');
    return main;

If someone know the answer I would be really glad. please in case you put minus explain while like that I can improve the post ;)

0

At the end of this line "AjaxUrl": "<?php echo $block->getAjaxUrl(); ?>", there is a comma (,) that should not be there.
Make the line look like this "AjaxUrl": "<?php echo $block->getAjaxUrl(); ?>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.