Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

$.getJSON doesn't do anything

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

$.getJSON doesn't do anything

Postby mblascog » Tue Feb 26, 2013 12:21 am

Hi,
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 -->
        </select>


And when the value of the selectbox changes, the following function is called:
Code: Select all
$(function(){

   $("select#ctl").change(function(){

     alert("before"+$(this).val())
   

   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.
mblascog
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Feb 26, 2013 12:00 am

Re: $.getJSON doesn't do anything

Postby mblascog » Tue Feb 26, 2013 5:57 am

Buenas,
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.

Gracias.
mblascog
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Feb 26, 2013 12:00 am

Re: $.getJSON doesn't do anything

Postby sandeep605085 » Tue Feb 26, 2013 10:43 am

Hi,

does the page select.php mentioned in the below path, return/echo the data in json format?
http://localhost:8887/fincamps/es/select.php

Below is the complete solution which works fine.

test.php
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("select#ctl").change(function(){
alert("before"+$(this).val());
var temp_val = $(this).val();

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

select.php
<?php
$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.

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

Re: $.getJSON doesn't do anything

Postby mblascog » 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.
mblascog
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Feb 26, 2013 12:00 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], landi and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.