opencart 2.0 SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data OK

12,670

Solution 1

I got the same error and found away to fix it:

  1. Login in the backend as admin and go to System > Users > Api
  2. Create a new api with a generated password and make sure it's enabled
  3. Go to your store settings (system > settings > Edit) and open the Option tab
  4. Scroll down till you find the 'checkout'
  5. Where it says 'API User' select the API User you just created
  6. Save the changes and your done!

You'll be able to edit the order status now!

Solution 2

I happened to have the same update order issue.

If you tried every possible solution found on the Internet, but no one worked, maybe the bug is from your server provider.

In my case, the problem comes from $curl function, which used frequently on opencart 2.0.

You may paste this php file in your admin/controller/sale/ and then type your url :http://YOURDOMAIN.com/admin/controller/sale/test.php

    <?PHP
            echo "a<br/>";
            $curl = curl_init();
      //http://YOURDOMAIN.com testing"

            $aa='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36 OPR/28.0.1750.48';
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLINFO_HEADER_OUT, true);
            curl_setopt($curl, CURLOPT_USERAGENT, $aa);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_URL,  'http://YOURDOMAIN.com/index.php?route=api/login');

            curl_setopt($curl, CURLOPT_POST, true);


            $json = curl_exec($curl);
            echo "server link to http://YOURDOMAIN.com/index.php?route=api/login <br/>";
            echo "Error Message:<br/>";
            print_r(curl_error($curl));
            echo "<br/>";
            echo "Response:";
            echo "<br/>";
            print_r($json);
            echo "<br/>";
            echo "<br/>";
            echo "<br/>";
            echo "<br/>";
            curl_close($curl);
            $curl = curl_init();
        //http://google.com"

            $aa='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36 OPR/28.0.1750.48';
            curl_setopt($curl, CURLOPT_HEADER, false);
            curl_setopt($curl, CURLINFO_HEADER_OUT, true);
            curl_setopt($curl, CURLOPT_USERAGENT, $aa);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_URL,  'http://google.com');

            curl_setopt($curl, CURLOPT_POST, true);


            $json = curl_exec($curl);
            echo "server lint to http://google.com <br/>";
            echo "Error Message:<br/>";
            print_r(curl_error($curl));
            echo "<br/>";
            echo "Response:";
            echo "<br/>";
            print_r($json);
            curl_close($curl);
       ?>

If your browser message doesn't show this

a server link to http://YOURDOMAIN.com/index.php?route=api/login Error Message:

Response: {"error":"\u8b66\u544a\uff1a\u4e0d\u5339\u914d\u7684\u7528\u6236\u540d\u6216\u5bc6\u78bc\u3002"}

Then you may ask your server provider to help you setting the server, because this means your $curl could not link to your localhost and could not retrieve data from your localhost.

Hope this will help you !!

Solution 3

I was able to solve this problem in 3 steps. In my case, i did upgrade my opencart database from 1.5x to 2.x with the standard (out of the box Opencart upgrade). I also had a multistore configuration. I was able to Edit orders once I run the following steps:

  1. Install OC2 (out of the box, no configuration) with the same admin credential as the one used in your legacy database. Export your database and find the place in the dump file (sql) where you have INSERT INTO api values (... line. This is the first command you need to run in you legacy database.

  2. UPDATE setting set value=1 where key = 'config_api_id';

  3. UPDATE store set ssl=url; However, this may not work if you are working on localhost. So for testing, I had to change it to UPDATE store set ssl = 'http://localhost/'; Do not forget the last backslash.

Please notice that you can also perform those operation on the admin user interface.

Solution 4

I had the issue, simple solution that works, try this:

Open Admin/Config.php

define('HTTPS_SERVER', 'http://yourdomain.com/admin/');
define('HTTPS_CATALOG', 'http://yourdomain.com/');

Change to the following:

define('HTTPS_SERVER', 'https://yourdomain.com/admin/');
define('HTTPS_CATALOG', 'https://yourdomain.com/');

Solution 5

Ive had a lot of issues upgrading from opencart 1.5.1 to 2.0.1

Exactly the same symptoms as yours

SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

So I created a fresh database and a fresh install of opencart 2.0.1

Initially I had no issues with new orders but as more orders where added and history ammended I got the same eror intermittently.

The only way around this was to clear cookies, close browser , reboot the laptop i was using, use an alternative browser. or login to another computer to change the history status.

this message seems to just seem to come up randomly when opencart feels like it

Really I should have just stayed with old version i would have saved 3 days mucking about fixing 'issues' in a version thats obviously not ready for production yet.

Share:
12,670

Related videos on Youtube

user2242141
Author by

user2242141

Updated on September 15, 2022

Comments

  • user2242141
    user2242141 over 1 year

    I looked all over the internet and found no answer.

    Basically my problem is whenever I try to edit orders and change stores I get the SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data OK in firefox and in chrome I get SyntaxError: Unexpected end of input OK.

    Has anyone found a "real" solution for this because I tried all that was suggested but they don't work. From changing the api_id to making a secondary API. And even the .htaccess method.

  • user2242141
    user2242141 about 9 years
    your steps didn't work and I did have tried that before but thank you. I think it has something to do with changing stores that gives the error. I just don't know how to fix this changing store problem but thanks though.
  • user2242141
    user2242141 almost 9 years
    our OC is actually 2.0.1.1 and i did try your method in the past and no avail it failed thanks anyways though...
  • user2242141
    user2242141 almost 9 years
    I tried this method but i still couldn't update the store in the orders page still the same error... thanks for the suggestion...