GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.38k stars 4.06k forks source link

SyntaxError: Unexpected token < in JSON at position 0 in storageManager, contentTypeJson: true, #879

Closed rajatkumcom closed 6 years ago

rajatkumcom commented 6 years ago

WARNING

READ and FOLLOW next 5 steps, then REMOVE them before posting the issue

  1. Follow CONTRIBUTING Guidelines https://github.com/artf/grapesjs/blob/master/CONTRIBUTING.md
  2. Use the GitHub Issues EXCLUSIVELY for BUGS, FEATURE REQUESTS or QUESTIONS. Prefix the title of the issue with its context, eg. [Bug]: ....
  3. Do a quick SEARCH first, to see if someone else didn't open the same issue
  4. DON'T ASK to create examples/code for you, read DOCS and APIs first, then you can post what you have tried (we'd like to see your code) and what you're unable to achieve
  5. All relative statements/questions have to be filled/answered, otherwise, the issue might be CLOSED

You're submitting a BUG

  1. Are you using the latest release (older versions are NOT supported)?
    1. If you're not sure, type grapesjs.version in console and press ENTER
  2. Are you facing the bug with your local copy of GrapesJS or with the current demo?
  3. If a local copy
    1. Indicate all informations about your OS, browser and GrapesJS version.
    2. Are you able to reproduce the bug from the demo?
  4. What is the expected behavior?
  5. What happens instead?
  6. If you're able to reproduce the bug indicate all the necessary steps
  7. Attach screenshots (using KAP/LICEcap), screencasts or live demo
    1. JSFiddle Starter template https://jsfiddle.net/szLp8h4n
    2. CodeSandbox Starter template https://codesandbox.io/s/1r0w2pk1vl

You're submitting a FEATURE REQUEST

  1. Be sure to work on the latest version, as the feature might be already there
  2. Keep in mind that the feature should be considered valid to use for everyone, not only for your case
rajatkumcom commented 6 years ago

Getting this error ( SyntaxError: Unexpected token < in JSON at position 0 ) when trying to use:- storageManager: { type: 'remote', autosave: false, setStepsBeforeSave: 1, contentTypeJson: true, params: {}, storeComponents: true, storeStyles: true, storeHtml: true, storeCss: true, urlStore: 'http://localhost/grapesjs/fileUpload.php', urlLoad: 'http://localhost/grapesjs/fileLoad.php', }

Could someone please help me... Thanks in advance!

v8jupiter commented 6 years ago

Can you give more details?

  1. Your have this error when trying to load template from 'http://localhost/grapesjs/fileLoad.php'?
  2. Or you have error in init moment. Can you show full initialization of editor?

I think your problem in this endpoint http://localhost/grapesjs/fileLoad.php.

rajatkumcom commented 6 years ago

When I am trying to save, then I got that error. Loading is perfect.

rajatkumcom commented 6 years ago

This is my code:-

rajatkumcom commented 6 years ago

I have done changes in grapes.js file which is not recommended var typeJson = this.get('contentTypeJson'); var typeJson = false;

Resolved issue.

maxtacco commented 6 years ago

No need to modify GrapesJS code. Just set 'contentTypeJson' to false in storeManager config if your endpoint uses application/x-www-form-urlencoded when storing the template.

var editor = grapesjs.init({
    ...
    storageManager: {
        ...
        contentTypeJson: false,
        ...
        }
    });
    ....
rajatkumcom commented 6 years ago

If I will set it as false, So while loading it creates problem.

rajatkumcom commented 6 years ago

It generate this output in console:-

Loaded {0: "{", 1: """, 2: "g", 3: "j", 4: "s", 5: "-", 6: "h", 7: "t", 8: "m", 9: "l", 10: """, 11: ":", 12: """, 13: "<", 14: "f", 15: "o", 16: "r", 17: "m", 18: " ", 19: "c", 20: "l", 21: "a", 22: "s", 23: "s", 24: "=", 25: "\", 26: """, 27: "f", 28: "o", 29: "r", 30: "m", 31: "\", 32: """, 33: ">", 34: "<", 35: "d", 36: "i", 37: "v", 38: " ", 39: "c", 40: "l", 41: "a", 42: "s", 43: "s", 44: "=", 45: "\", 46: """, 47: "f", 48: "o", 49: "r", 50: "m", 51: "-", 52: "g", 53: "r", 54: "o", 55: "u", 56: "p", 57: "\", 58: """, 59: ">", 60: "<", 61: "l", 62: "a", 63: "b", 64: "e", 65: "l", 66: " ", 67: "c", 68: "l", 69: "a", 70: "s", 71: "s", 72: "=", 73: "\", 74: """, 75: "l", 76: "a", 77: "b", 78: "e", 79: "l", 80: "\", 81: """, 82: ">", 83: "N", 84: "a", 85: "m", 86: "e", 87: "<", 88: "\", 89: "/", 90: "l", 91: "a", 92: "b", 93: "e", 94: "l", 95: ">", 96: "<", 97: "i", 98: "n", 99: "p", …}

artf commented 6 years ago

@rajatkumcom your server have to set a correct header output, eg. in php it should be something like this

header('Content-Type: application/json');
echo json_encode($data);
rajatkumcom commented 6 years ago

Thank you....

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.