javascript - Uncaught SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) -
i trying postings in database list. keep getting error saying
uncaught syntaxerror: unexpected token < in json @ position 0 @ json.parse (<anonymous>) @ object.success (open:42) @ j (jquery.min.js:2) @ object.firewith [as resolvewith] (jquery.min.js:2) @ x (jquery.min.js:5) @ xmlhttprequest.b (jquery.min.js:5)
i applied codes https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql-part-4--cms-23187 , works when followed same way. doing notice board, , should return stored postings when open page. need helps. thanks. below codes.
app.py
@app.route('/getopenlist') def showopenlist(): try: if session.get('user'): con = mysql.connect() cursor = con.cursor() cursor.callproc('sp_showopenlist') openlist = cursor.fetchall() openlist_dict = [] lists in openlist: openlist_dict = { 'id': lists[0], 'title': lists[1], 'content': lists[2], 'writer': lists[3], 'date': lists[4]} listopen_dict.append(openlist_dict) return json.dumps(listopen_dict) else: return render_template('error.html') except exception e: return render_template('error.html')
sp_showopenlist "select * open".
ann_etc.html
.... <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" href="/static/css/style.css"/> <script type="text/javascript" src="phonegap.js" charset="utf8"></script> <script src="../static/js/jquery.min.js"></script> <script> $(function(){ $.ajax({ url : '/getopenlist', type : 'get', success: function(res){ var openobj = json.parse(res); $('#ulist').empty(); $('#listtemplate').tmpl(openobj).appendto('#ulist'); }, error: function(error){ console.log(error); } }); }); </script> </head> <script id="listtemplate" type="text/x-jquery-tmpl"> <li class="list-group-item"> <div class="checkbox"> <label> ${id} | </label> </div> <div class="checkbox"> <label> ${title} | ${writer} | ${date} </label> </div> </li> </script> <div class="row"> <div class="col-md-12"> <div class="panel-body"> <ul id="ulist" class="list-group" display="inline-block"> </ul> </div> </div> </div>
Comments
Post a Comment