$.getJSON doesn't do anything

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Tue Feb 26, 2013 12:21 am

Till now I've been programming ASP webs. Now a costumer has ordered me to modify a php web that other people have written.
The first thing I've done is to download it to my pc. I'm just studying it and I've got a problem. After a lot of hours trying to find a solution I've decided to ask for it, if somebody can help me.
The problem is that $.getJSON doesn't work and no error is shown.
The code is this:

Code: Select all

        <select name="id0" id="ctl">
               <option value="" <?php if($id0_sel == ""){echo ' selected="selected" ';}?>><?PHP echo $tit_selecciona;?></option>		<!-- Introducir operación -->
               <option value="4" <?php if($id0_sel == "4"){echo ' selected="selected" ';}?>><?PHP echo $tit_buscador0_1;?></option>	<!-- Venta -->
               <option value="3" <?php if($id0_sel == "3"){echo ' selected="selected" ';}?>><?PHP echo $tit_buscador0_2;?></option>	<!-- Alquiler -->
And when the value of the selectbox changes, the following function is called:

Code: Select all




	var temp_val = $(this).val();
		$.getJSON("http://localhost:8887/camp/es/select.php",{id0: $(this).val()}, function(j){
			var options = '';

			alert ("after");
The first alert works, "before" with the correct value, but the second, after, is never show.
I've changed the web, only select.php, and doesn't work
This web is working fine in a server.

I've installed EasyPHP, PHP 5.4.6, Apache 2.4
I have no idea about the problem. Perhaps configuration, perhaps code. Please help me!!! Thanks
Last edited by mblascog on Tue Feb 26, 2013 9:56 pm, edited 1 time in total.


Tue Feb 26, 2013 5:57 am

Usando la cónsola de errores me he dado cuenta que la página select.php contenía un error. Una vez arreglado ha funcionado.


User avatar
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions

Tue Feb 26, 2013 10:43 am


does the page select.php mentioned in the below path, return/echo the data in json format?

Below is the complete solution which works fine.

<script src="http://ajax.googleapis.com/ajax/libs/jq ... ery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var temp_val = $(this).val();

$.getJSON("http://test/test3.php",{id0: $(this).val()}, function(j){
var options = '';
alert ("after");
<select name="id0" id="ctl">
<option value="">1</option> <!-- Introducir operación -->
<option value="4">2</option> <!-- Venta -->
<option value="3">3</option> <!-- Alquiler -->

$array = array(
"one"=> "Singular sensation",
"two"=> "Beady little eyes",
"three"=> "Little birds pitch by my doorstep"

echo json_encode($array);

so basically $.getJSON require the return result in the format of json. so please return the data from your select.php in json format.

Sandeep Agrawal


Tue Feb 26, 2013 2:05 pm

Thanks for your answer. This afternoon I've answered myself, but I've done it in spanish instead of english (sorry). I had a mistake in select.php. I saw it using the console.
Thanks again.

Post Reply