php - Ajax request returns POST <<url>> 500 (Internal Server Error) -


i've been doing module website using wamp server , works, when upladed website server returns error 500.

error 500 1

error 500 2

when main page index.php loads (using javascript .ready function) send ajax request 'obtenermunicipio.php'.

<script type="text/javascript">     $( document ).ready(function() {         $.ajax({           type: 'post',           url: '../obtenermunicipio.php',           data : {'valor':'paz'},           datatype: 'json',           success: function(data) {             if(data.length <= 0) {               return;             }             for(var i=0; < data.length; i++) {                 var opcion = document.createelement('option');                 opcion.innerhtml+=data[i];                 document.getelementbyid('unidadmedica').appendchild(opcion);             }           },           error: function(e) {             console.log(e.message);           }         });      }); </script> 

the page 'obtenermunicipio.php' receive value 'valor' , made mysql query obtain array data it's return.

<?php     include($_server['document_root'].'/noticias/conexion.php');     header('content-type: text/html; charset=iso-8859-15');     header("application/json");     $conexion=conectar();     $municipio = utf8_decode($_post['valor']);     if($municipio != "loret")         $sql = "select distinct unidadmedica `unidadesmedicas` municipio '%".$municipio."%' , localidad not '%loret%'";     else         $sql = "select distinct unidadmedica `unidadesmedicas` localidad '%".$municipio."%'";     $rs = mysql_query($sql) or die(mysql_error($conexion));      $fila = mysql_fetch_all($rs);     print json_encode($fila); ?> 

any ideas of how solve it? works fine on wamp.

i'm putting inside reply instead of comment because feel getting hard keep track of since there multiple things say.

error 500 means there's wrong php script not handled correctly web server. it's undeclared (or deprecated) function or issue paths or extensions.

the first step follow in order investigate issue either finding error_log file on web server, or pasting these 2 lines @ top of php script:

<?php error_reporting(-1); // highest error reporting level ini_set("display_errors", true); // print errors directly output /* rest here */ 

that said, there 1 more issue code! aware it's vulnerable against sql injection attacks since you're building query string directly , else might have query totally different.

to solve that, should either use pdo , mysqli extensions' prepared statements or pass variables you're going use in query string through mysql_real_escape_string().


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -