Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery not loading data on a select
    primarykey
    data
    text
    <p>I have a main PHP page that uses jQuery to load the different pages for actions that the user can do.</p> <p><img src="https://i.stack.imgur.com/96zbK.png" alt="Main page"></p> <p>This is where the user do everything. It has an jQuery script that when you click an orange element <code>&lt;p&gt;</code>.</p> <p>When you click "Solicitar Software", jQuery loads "solicitudes.php". This php page has its own script.</p> <p><img src="https://i.stack.imgur.com/x78V4.png" alt="enter image description here"></p> <p>When "solicitudes.php" page loads, its PHP script runs. <pre><code>require('conexion.php'); $conexion = new connection(); $query = "SELECT * FROM Carreras"; $resultado = mysql_query($query, $conexion -&gt; conn) or die('ERROR:' .$query); ?&gt; </code></pre> <p>The script loads all the careers in the database and add add them to the <code>&lt;select&gt;</code> as you can see:</p> <p><img src="https://i.stack.imgur.com/DQCBt.png" alt="enter image description here"></p> <p>The problem is here, when I click on a carrer, it does not load the list subjects related to the career. But, if I access the PHP file alone, it works well.</p> <p><img src="https://i.stack.imgur.com/OzwfE.png" alt="enter image description here"></p> <p>Here is the jQuery code:</p> <pre><code>$(document).ready(function() { $("#carrera").change( //Select a carrer function() { var carreraId = $('#carrera option:selected').val(); var queryMaterias = "carreraid=" + carreraId + "&amp;valor=" + $("#valor").val(); jQuery.ajax({ url: 'acciones.php', type: 'GET', dataType: 'text', data: queryMaterias, success: function(data) { $("#lmateria").empty(); $("#lmateria").append(data); //Add subjects to the &lt;select&gt; // $("#lmateria").html(data); }, error: function(xhr, textStatus, errorThrown) { //called when there is an error alert(errorThrown); }, }); } ); }); </code></pre> <p>Am I doing something wrong? What may be the problem? Thanks for the help.</p> <p>Main page: </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Sistema de Administración&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="//necolas.github.com/normalize.css/2.1.0/normalize.css"&gt; &lt;link rel="stylesheet" type="text/css" href="css/administrador.css"&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="scripts/administrador.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="acciones"&gt; &lt;p id="logo"&gt; &lt;img src="images/logo1.jpg" alt="logo"&gt; &lt;/p&gt; &lt;p id="division"&gt;Agregar Division&lt;/p&gt; &lt;p id="carrera"&gt;Agregar Carrera&lt;/p&gt; &lt;p id="materia"&gt;Agregar Materia&lt;/p&gt; &lt;p id="software"&gt;Agregar Software&lt;/p&gt; &lt;p id="profesor"&gt;Agregar Profesor&lt;/p&gt; &lt;p id="ssoftware"&gt;Solicitar Software&lt;/p&gt; &lt;p id="solicitudes"&gt;Lista de Solicitudes&lt;/p&gt; &lt;center&gt;&lt;input type="button" id="logout" value="Salir" onclick="window.location.href='acciones.php?valor=5'"&gt;&lt;/center&gt; &lt;/div&gt; &lt;div id="resultado"&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>jQuery loads "solicitud.php" on the <code>&lt;div&gt; resultado</code>.</p> <p>Solicitud.php:</p> <pre><code>&lt;!doctype html&gt; &lt;?php require('conexion.php'); $conexion = new connection(); $query = "SELECT * FROM Carreras"; $resultado = mysql_query($query, $conexion -&gt; conn) or die('ERROR:' .$query); ?&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;link rel="stylesheet" type="text/css" href="css/solicitud.css"&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="scripts/solicitud.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;header&gt; &lt;h2&gt;Solicitud de Software&lt;/h2&gt; &lt;/header&gt; &lt;form action="acciones.php" id="solicitud" method = "GET"&gt; &lt;select name="carrera" id="carrera"&gt; &lt;option value=""&gt;Seleccione una carrera&lt;/option&gt; &lt;?php while ($datos = mysql_fetch_assoc($resultado)) #MUESTRA LOS ROLES { ?&gt; &lt;option value="&lt;?php echo $datos['id'];?&gt;"&gt;&lt;?php echo utf8_encode($datos['Carrera']);?&gt;&lt;/option&gt; &lt;?php } ?&gt; &lt;/select&gt; &lt;select name="materias" id="lmateria"&gt; &lt;option value=""&gt;Potato&lt;/option&gt; &lt;/select&gt; &lt;!-- &lt;input type="text" placeholder="Nombre" id="nombre" name="nombre"&gt; &lt;input type="text" placeholder="Codigo" id="codigo" name="codigo"&gt; &lt;input type="button" value="Agregar" id="enviar"&gt; --&gt; &lt;input type="hidden" id="valor" name="valor" value='17'&gt; &lt;/form&gt; &lt;h3 id="exito"&gt;Agregado!&lt;/h3&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload