php - Returned json from connecting to mysql via ajax in login has html code in it -


i developing login option on website. make jquery ajax call

$.ajax({     beforesend: function () {         //verificar si hay mensaje de error         if ($('#loginerror').is(':visible')) {             $('#loginerror').addclass('hide');         }         $('#ajaxloader').removeclass('hide');     },     cache: false,     type: "post",     datatype: "json",     url: "includes/appresponses.inc.php",     data: str + "&accion=login&id=" + math.random(),     success: function (response) {         //verificar errores         if (response.respuesta == true) {             alert(response.mensaje);             window.location.href = "index.php";             $('#loginerror').addclass('hide');         } else {             $('#loginerror').removeclass('hide');         }          $('#ajaxloader').addclass('hide');     },     error: function (jqxhr, textstatus, errorthrown) {         alert("error general. " + textstatus + ". " + errorthrown);     } }); 

when use a login returns normal json object when fail login return error:

syntaxerror: json.parse: unexpected character @ line 1 column 1 of json data 

because returned "json" this:

 <br /> <font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>     <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> warning: mysqli::mysqli(): (hy000/1045): access denied user 'roots'@'localhost' (using password: yes) in c:\wamp\www\cazares\includes\mainfunctions.inc.php on line <i>37</i></th></tr>     <tr><th align='left' bgcolor='#e9b96e' colspan='5'>call stack</th></tr>     <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>time</th><th align='left' bgcolor='#eeeeec'>memory</th><th align='left' bgcolor='#eeeeec'>function</th><th align='left' bgcolor='#eeeeec'>location</th></tr>     <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0000</td><td bgcolor='#eeeeec' align='right'>248760</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='c:\wamp\www\cazares\includes\appresponses.inc.php' bgcolor='#eeeeec'>..\appresponses.inc.php<b>:</b>0</td></tr>     <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>265568</td><td bgcolor='#eeeeec'>include( <font color='#00bb00'>'c:\wamp\www\cazares\includes\mainfunctions.inc.php'</font> )</td> <td title='c:\wamp\www\cazares\includes\appresponses.inc.php' bgcolor='#eeeeec'>..\appresponses.inc.php<b>:</b>17</td> </tr> <tr>     <td bgcolor='#eeeeec' align='center'>3</td>     <td bgcolor='#eeeeec' align='center'>0.0010</td>     <td bgcolor='#eeeeec' align='right'>267256</td>     <td bgcolor='#eeeeec'><a href='http://www.php.net/mysqli.mysqli' target='_new'>mysqli</a> ( )</td>     <td title='c:\wamp\www\cazares\includes\mainfunctions.inc.php' bgcolor='#eeeeec'>..\mainfunctions.inc.php<b>:</b>37</td> </tr> </table> </font>{"respuesta":false,"mensaje":"error al conectar con la base de datos","contenido":""} 

my connection made this:

if (defined('server') && defined('user') && defined('pass') && defined('maindatabase')) {      $mysqli = new mysqli(server, user, pass, maindatabase);      if (mysqli_connect_errno()) {         $errordbconexion = true;     } else {         //evitando problemas con acentos         $mysqli - > query('set names "utf8"');     } } 

you have xdebug enabled , generates 'pretty' error messages formatting them display using html.

the error message xdebug trying show is:

warning: mysqli::mysqli(): (hy000/1045): access denied user 'roots'@'localhost' (using password: yes) in c:\wamp\www\cazares\includes\mainfunctions.inc.php on line 37 

you should fix error in php code , returned json valid.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -