LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-16-2014, 07:16 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
Smile Can't display data returned from AJAX call


Hi,

This result;

[{"bakfile":"~\/DB-Web\/accounts\/ACCOUNTS_DUMP_06.16.14_11.30.27.sql.gz"},{"bakfile":"~\/DB-Web\/contacts\/CONTACTS_DUMP_06.16.14_11.30.07.sql.gz"}]

is what is returned from the PHP code shown below.

The <script> is what I am trying to read the "data" from. It gives me "bakfile undefined" as the result. I'm thinking this is some stupid thing I am doing but I can't figure it out. Any help here appreciated !!!


Code:
<script type="text/javascript" >

	$(function() {
				$.ajax({
				type: "POST",
				url: "restore.php",
				datatype:"json",
				success: radioPick             // <<= === === CALLBACK FUNCTION
			}); // ajax
			
			function radioPick(data) {
				
		alert("\nbakfile\n"+ data[0].bakfile);
					
				}
		
		});

</script>
And the Server Code PHP

Code:
  			$rows=array();

  $cxn = mysqli_connect($hostname,$username,$password,$database)   
         or die ("couldn't connect to server");

  $query = "SELECT bakfile FROM ".$table." ORDER BY bakfile";
      
  $result = mysqli_query($cxn,$query)  or die ("Couldn't execute query.");
                                     
  while($row = mysqli_fetch_assoc($result))  {  
     
     //extract($row); 
     
       //if($row['bakfile']=="") { continue;} 

     $rows[]=$row;
   }

  echo json_encode($rows);
 
Old 06-17-2014, 04:21 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
The function radioPick expects a parameter but you do not give it, do you?
 
Old 06-17-2014, 01:37 PM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Smile

[SOLVED]

I went back and reviewed a JSON tutorial. I needed to use JSON.parse() to access the 'data' returned from AJAX.

The function radioPick expects a parameter but you do not give it, do you? The 'data' returned by AJAX is the parameter.

Thanks for the help.

R

Code:
<script type="text/javascript" >

	$(function() {
				$.ajax({
				type: "POST",
				url: "restore.php",
				datatype:"json",
				success: radioPick             // <<= === === CALLBACK FUNCTION
			}); // ajax
			
			function radioPick(data) {

				var selection=JSON.parse(data);
				
				alert(selection[0].bakfile);
				alert(selection[1].bakfile);	
					
				}
		
		});

</script>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nfs :RPC call returned error 101 sindhumaheswari Linux - Newbie 2 02-23-2010 06:23 PM
Samba: 2317 - Call returned zero bytes (EOF) tungvs Linux - Server 0 06-14-2008 02:23 PM
nfs: RPC call returned error 101 alphalzw Linux - Networking 1 08-31-2006 06:11 PM
RPC call returned error 1 toneys Red Hat 0 05-06-2006 05:00 AM
tracing the error code returned by wait call lg3 Linux - Software 0 02-21-2005 03:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration