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">
          <% _.each(posts, function(text,value) { %>
             <option value="<%= value %>"><%= text %></option>
          <% }) %> 
         </select> </div>

and here js:

    ], function (
    ) {
        function main(config, element) {
            var $element = $(element);
            var zipurl = config.AjaxUrl;
            $(document).on('click','#zip_btn',function() {
                    var param = 'ajax=1';
                            showLoader: true,
                            url: zipurl,
                            data: param,
                            type: "POST",
                            dataType: 'json'
                        }).done(function (data) {
                            var html = template('#test', {posts:data}); 
    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 ;)


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.