Search the Community
Showing results for tags 'jsonp'.
-
You guys always help. I'm NOT a javascript programmer but am learning slowly. Here's the situation: I'm loading dynamic content I originally created for PHP and MySql for this sites main page. No problems there. I savvy PHP. But now I'm building a phone app using juerymobile (mostly... lot's of custom javascript in there as well). So I'm calling for the dynamic content to be loaded via AJAX and JSONP. No problems there either. (basically getting that info from a PHP file of course that gets the info from the database). Now in PHP once I have that ID for the content I want I can manipulate things to my hearts desire. Since I'm not a javascript programmer it's hard for me to wrap my head around the way to accomplish what I can with PHP. I'm truncating data. I want to slide to a new view when an arrow is clicked. So I don't have to call for the data again, I'm hiding a div that slides into view when clicked. But I need the content of that particular row (in MySql) and only that row to appear in that div. I have that data in a var but since it's in a loop.... I can pass the ID on to javascript if that helps. Some good reading would be nice to increase my learning. Stupid class I took online didn't get into these kinds of details. Thanks!
-
Ok. I have the jsonp working the way it should and I get the info back from a cross domain url. I copied the truncate portion of this code but it doesn't seem to be working for me. What's wrong with this code? I know it will be obvious but I'm new to javascript. :-) <script type="text/javascript"> $(function(){ var minimized_elements = $('p.minimize'); minimized_elements.each(function(){ var t = $(this).text(); if(t.length < 100) return; $(this).html( t.slice(0,100)+'<span>... </span><a href="#" class="more">More</a>'+'<span style="display:none;">'+ t.slice(100,t.length)+' <a href="#" class="less">Less</a></span>' ); }); $('a.more', minimized_elements).click(function(event){ event.preventDefault(); $(this).hide().prev().hide(); $(this).next().show(); }); $('a.less', minimized_elements).click(function(event){ event.preventDefault(); $(this).parent().hide().prev().show().prev().show(); }); $.get("http://www.somedomain.com/app_ajax.php?callback=?", function(data, textStatus){ $.each(data, function(index, user){ var newDiv = '<div class="prayer_received">' var newName = '<div class="name"><h2>' + (user.name) + '</h2></div>'; var newRequest = '<div class="prayer"><p class="minimize">' + (user.request) + '</p></div>'; var newDate = '<div class="date"><p>Posted on' + (user.date) + '</p></div>'; var newTimes = '<div class="times"><p>Prayed for' + (user.times) + ' times</p></div>'; var newRule = '<div class="rule"><hr></div></div>'; $("#request").append(newDiv + newName + newRequest + newDate + newTimes + newRule); }); }, "json" ); }); </script>