Uncaught SyntaxError: Unexpected end of JSON input error when i try to take data from mysql

Bogdan Bibina

I try to make to load the content from mysqldb using an animation and a limit of content taken and it takes content is displaying when it gets at the end of content the animation of loading is continue loading a I get this error

My script:

<script>

    $(document).ready(function(){

     var limit = 7;
     var start = 0;
     var action = 'inactive';
     function load_country_data(limit, start)
     {
      $.ajax({
       url:"/select_index",
       method:"POST",
       data:{limit:limit, start:start},
       cache:false,
       success:function(data)
       {
        var obj2 = JSON.parse(data);
            console.log(data);
            console.log(obj2);
            var i=0;
            var j=0;

        for(i in obj2){
        //for(j in obj2[i]){
       $('#load_data').prepend("<form><div class='panel panel-white post panel-shadow user-post'><div class='post-heading'><div class='pull-left image'><img src='static/"+obj2[i][4]+"' class='img-circle avatar' alt='user profile image'></div><div class='pull-left meta'> <div class='title h5'><a href='#'><b>"+obj2[i][1]+"</b></a> made a post.</div><h6 class='text-muted time'>1 minute ago</h6></div></div> <div class='post-description'> <p>"+obj2[i][0]+"</p><div class='stats'><a href='#' class='btn btn-default stat-item'> <i class='fa fa-thumbs-up icon'></i>2</a> <a href='#' class='btn btn-default stat-item'><i class='fa fa-share icon'></i>12</a></div></div><div class='post-footer'><div class='input-group'> <input class='form-control' placeholder='Add a comment' type='text'></div>                </div></div></form>" );
     //  }
     }


       // $('#load_data').append(data);
        if(data == '')
        {
         $('#load_data_message').html("No Data Found");
         action = 'active';
        }
        else
        {
         $('#load_data_message').html("<div class='loadingC'><div class='loadingCcerc'</div></div>");
         action = "inactive";
        }
       }
      });
     }

     if(action == 'inactive')
     {
      action = 'active';
      load_country_data(limit, start);
     }
     $(window).scroll(function(){
      if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
      {
       action = 'active';
       start = start + limit;
       setTimeout(function(){
        load_country_data(limit, start);
       }, 800);
      }
     });

    });
    </script>

I see something that the error came from json.parse My python script:

@app.route('/select_index',methods=["POST","GET"])
def select_index():
    limit=request.args['limit']
    print(limit)
    start=request.args['start']
    print(start)
    select="SELECT comments.post,comments.name,comments.post_id , register.id,register.profile_pic,comments.id FROM comments,register WHERE register.id=comments.post_id ORDER  BY comments.id DESC LIMIT "+str(start)+","+str(limit)+" "
    con.execute(select)
    fetch=con.fetchall()
    print(fetch)
    json_fetch=str(jsonify(fetch))
    print(len(json_fetch))
    if json_fetch=="<Response 3 bytes [200 OK]>":
        return ""
    else:        
        return jsonify(fetch)
Sven Writes Code

You are returning an empty string from your python code:

if json_fetch=="<Response 3 bytes [200 OK]>":
    return ""

When you use JSON.parse(""), you are returned with the Uncaught SyntaxError: Unexpected end of JSON input

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error: Uncaught SyntaxError: Unexpected end of JSON input

Uncaught (in promise) SyntaxError: Unexpected end of JSON input error

JavaScript error (Uncaught SyntaxError: Unexpected end of input)

Error "Uncaught SyntaxError: Unexpected end of input"

Uncaught SyntaxError: Unexpected end of JSON input [}

Error: SyntaxError: Unexpected end of JSON input when using fetch()

Uncaught SyntaxError: Unexpected end of input

Even with Try{} Catch (e){} the script does not ignore the error -> Uncaught (in promise) SyntaxError: Unexpected end of Json Imput

Error : SyntaxError: Unexpected end of JSON input

Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse?

Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>)

Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse

Uncaught SyntaxError: Unexpected end of JSON input. Can't properly parse the info to JSON from the html

Js error: "Uncaught (in promise) SyntaxError: Unexpected end of input"

Uncaught SyntaxError: Unexpected end of input While doing JSON.Parse

React fetch results in Uncaught (in promise) SyntaxError: Unexpected end of JSON input

Uncaught (in promise) SyntaxError: Unexpected end of input after json fetch

PDFJsAnnotations Uncaught (in promise) SyntaxError: Unexpected end of JSON input

Angular, Uncaught SyntaxError: Unexpected end of input when moving to production

Return JSON from Express app: Uncaught (in promise) SyntaxError: Unexpected end of input

Uncaught SyntaxError: Unexpected token e when try to parse a JSON string

Uncaught SyntaxError: Unexpected end of input on a Composer dependency

Uncaught SyntaxError: Unexpected end of input (in the ending of the script)

Uncaught SyntaxError: Unexpected end of input JavaScript

Chrome: Uncaught SyntaxError: Unexpected end of input

Uncaught SyntaxError: Unexpected end of input in AJAX

MeteorJS Uncaught SyntaxError: Unexpected end of input

Laravel Swagger - Uncaught SyntaxError: Unexpected end of input

Uncaught SyntaxError: Unexpected end of input on line one