Why do I get SyntaxError: JSON.parse in bootstrap fileinput?

Web Tips Q & ACategory: Krajee PluginsWhy do I get SyntaxError: JSON.parse in bootstrap fileinput?
Kartik Staff asked 2 years ago

On installing the plugin as mentioned in the demo page and creating a test code to initialize the fileinput, the user gets an error that is trapped on the browser’s javascript console as SyntaxError: JSON.parse. 

This happens only when plugin is setup for an ajax mode for upload by setting the uploadUrl property of the plugin.

1 Answers
Kartik Staff answered 2 years ago

The following are the most likely reasons why this error is received.

  • Check your server code. For an ajax mode, the bootstrap-fileinput plugin requires the server to send a valid JSON response. So the server action that you set in plugin uploadUrl MUST send a valid JSON. The format of JSON to be sent from server is described in the documentation for asynchronous ajax uploads and synchronous ajax uploads. Note that even if you do not have a valid JSON to send – you must ensure that you return at least an empty JSON object like below:
    {}
  • The other reason for the error could likely be that you are not setting a valid uploadURL that is accessible – or –  there is a javascript / jQuery error or conflict on your page resulting in the plugin not getting a valid JSON from the ajax response.
pethum replied 2 years ago

please how to upload in asp.net web site, using webmethod.what is the method for UploadURL, any exmaple

Login or register to contribute or comment.

Login   Register