Jump to content

json object from flickr api to print to console

Recommended Posts

See: http://sulley.dm.ucf...nt2/viewer.html user enters a search term, then click submit. It should open the php file via the javascript click function which performs a cURL response then returns the JSON object to the javascript to parse. Right now im just trying to get the JSON object printed to the console in the javascript function. Can anyone see the issue? in developer tools the network response shows the JSON object but its not printing to console. html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>DIG4503 – Caitlin Havener Assignment 2</title><link rel="stylesheet" type="text/css" href="css/reset.css" /><link rel="stylesheet" type="text/css" href="css/styles.css" /><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript" src="js/a2.js"></script></head><body><div id="wrapper">	 <div id="header">		<img src="#" alt=""/>		<h1>A Case of the "Mondays"</h1>		</div>	  		<div id="content">		 <div id="search">			 <input type="text" id="searchText" />				<div id="submit"><h2>Submit</h2></div>			</div>			<div id="thumbs">			</div>			<div id="specific">			</div>		</div>	  		<div id="footer">		 <h1>Designed by Caitlin Havener with Flickr API, cURL, jQuery, XHTML</h1>		</div>	  	</div></body></html>


// JavaScript Document$(document).ready(function(){$("#submit").click(function(e){  e.preventDefault();  var txt=$("#searchText").val();  $.ajax(  {   url:'getThumbs.php',   data:  'text=' + txt,   type: 'POST',   dataType:'json',   success:function(data)   {	//parse	console.log('success');	console.log(data);	//object is in 'result'	//append responseXML (json) to #thumbs	//parse the json object and output images with jquery   },	  failure:  function(){		 console.log('failure')	  }});});});		


<?phpini_set('display_errors', 'on');/*should contain a PHP script that performs a cURL request for datafrom Flickr using the flickr.photos.search REST API and should return an XMLresponse.*/$ch = curl_init();$txt= $_POST['text'];$url = 'http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=ccb29e24bac7fd677e1e1ba0a4ae84fa&text=' . $txt . '&content_type=1&media=photos&per_page=40&format=json';curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_URL, $url);$curl_response = curl_exec($ch);curl_close($ch); //$rsp_obj = unserialize($curl_response);echo($curl_response); /*getThumbs.php should loop through the XML response and output a set of <img />elements that contain thumbnail URLs as the src attribute and the photo_id as the altattribute of each image ONLY for images that were taken on a Monday.*/ ?>

Link to post
Share on other sites



to the request URL in PHP,http://www.flickr.com/services/api/response.json.html and consider changing the click event to onhttp://api.jquery.com/on/

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...