Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts

    clipbucket javascript problem

    Hello, in the channel of a user in clipbucket, down page there are the tabs "Activity", "Infos", "Videos", "Groups" and "Photos"...
    When I click in Videos, Groups and Photos tabs clipbucket doesn't load and show them, could you help me solve this?
    the only problem sometimes I get in javascript error consol is "The object doesn't support the method appendTo". I marked red the line with the problem in the code below here.
    you can see the problem in this page, logging in with "arvixe" as username and password

    removed URL (NSFW)

    Thank you

    Code:
    function channelObjects(object,div,type,user,assign)
    {
    	var obj = $(object), curRel = obj.attr('rel'),
    		DIV = $(div), oldRel = obj.parents('ul').find('a.selected').attr('rel');
    	
    	if(curRel)
    	{
    		if($("#"+curRel).css('display') == 'block')
    			return false;
    		else
    		{
    			obj.parents('ul').find('a.selected').removeClass('selected');
    			obj.addClass('selected');
    			
    			$("#"+oldRel).hide();
    			$("#"+curRel).show();		
    		}
    	} else {
    		var newRel = type+"DIV";
    		obj.attr('rel',newRel);
    		$.ajax({
    		 url : page,
    		 type : "POST",
    		 dataType : "json",
    		 data : ({ mode : "channelObjects", content : type, user : user, assign : assign}),
    		 beforeSend : function() { obj.append(loading_img) },
    		 success : function(data)
    		 {
    			obj.find('img').remove();
    			obj.parents('ul').find('a.selected').removeClass('selected');
    			obj.addClass('selected');		
    		
    			$("#"+oldRel).hide();
    			$("<div></div>").attr('id',newRel).addClass($("#"+oldRel).attr('class')).html(data.html).appendTo(DIV); 
    		 }
    		})	
    	}
    Last edited by venegal; 12-17-2011 at 05:51 PM. Reason: removed URL

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    You're obviously expecting the request to return JSON, and that data is an object. It's not though (use your browser's debugging tools) — data is a string, so data.html is undefined.

    So, when calling .html(data.html), you're actually calling .html(undefined), which is the same as passing no parameter at all. If no parameter is passed, though, jQuery's html won't set the HTML and return the object, but get the HTML.

    This means that it returns a string, which obviously doesn't have an appendTo method.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I checked the official clipbucket demo and the function is exactly like mine so the problem isn't there and i don't know why it doesn't show them...
    I don't know json can you explain me how it works, there must be somewhere a php code associated with that javascript function and causing the problem?

    thank you!

  • #4
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    What I meant is: Your code makes an AJAX request to ajax.php, and tries to handle the response as JSON. The response isn't JSON, though, it's gibberish. As I said, use your browser's debugging tools to see the AJAX response, and debug your PHP code, so it actually sends JSON (meaning a serialized Javascript object — google it, if you don't know what that means).
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  • Users who have thanked venegal for this post:

    paperino00 (12-23-2011)

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I debugged the json response that is:

    Fatal error: Cannot use assign-op operators with overloaded objects nor string offsets in /home/mysite/public_html/ajax.php on line 1154.

    In clipbucket official demo it response correctly despite the code seems the same...

    this is part of ajax.php, I evidenced in red the line 1154, do you see something wrong? I didn't coded it and I'n not expert so i can't get out what's wrong...
    Thank you!

    Code:
    switch($contentType)
    			{
    				case "videos" :
    				{
    					$videos = get_videos(array("user"=>$u['userid'],"order"=>" date_added DESC","limit"=>config('videos_item_channel_page')));
    					
    					if($videos)
    					{
    						foreach($videos as $video)
    						{
    							assign('video',$video);
    							assign('channelVideo',true);
    							$content['html'] .= Fetch("/blocks/video.html");
    						}
    						$content['html'] .= '<div align="right" class="clearfix channelAjaxMoreLink videosMoreLink" style="clear:both; display:block;">';
    						$content['html'] .= '<a href="'.cblink(array("name"=>"user_videos")).$u['username'].'">'.lang('more').'</a> | <a href="'.cblink(array("name"=>"user_favorites")).$u['username'].'">'.lang('Favorites').'</a>';
    						$content['html'] .= '</div>';
    					} else {
    						$content['html'] = '<div align="center"><em>'.lang('user_have_no_vide').'</em></div>';	
    					}
    				}
    				break;

  • #6
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    It seems $content isn't what you think it is, but there's no way to know without seeing more of the code. If you need further help with this, please post in the PHP section of the forum.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •