Jump to content

Table Sort Not Working On Ajax Example


rokimomi
 Share

Recommended Posts

http://www.smashrok.com is my siteI wish to make the list generated after selecting an episode sortable but apparently ajax says otherwise. I know its not a fault of javascript cuz the jquery works fine when tested outside of the div that the ajax is assigned to replace. The tut is the ajax with php database example.http://www.w3schools.com/php/php_ajax_database.aspThis is the table sort. http://tablesorter.com/docs/Now, when I assign everything perfectly to the table output (meaning everything needed for JS to work properly is in place), It doesnt alow for the list to sort.My best hunch is that the javascript includes dont even apply to the php page that's called by the ajax, but how would I fix that? Thanks for any help.
Link to comment
Share on other sites

You have the ajax response being the entire table HTML, also with a link tag to a CSS file and several Javascript files. When you return Javascript files in ajax it's not going to execute the code, it's just using the ajax response as HTML text to assign to the innerHTML property (I assume, in this case). So it will put the script element on the page, but it's not going to execute the code. Instead of returning the stylesheet and script tags in the ajax response, include those once on the page and just have the ajax return the table markup. After the table is in place then you should be able to run this to make it sortable:$("#myTable").tablesorter();

Link to comment
Share on other sites

Ok, I have done what you said, taken out the javascript and css linking from the ajax called page and instead have them all just linked to from the index where the page is shown, but it still doesnt work. My setup is this:Main:Index -include browse.php-include jquery-1.3.2.min.js-include jquery.tablesorter.min.js-include sort.js

$(document).ready(function() 	{ 		$("#myTable").tablesorter(); 	} );

browse.php-uses the function on sort list to replace div for ajax called pageCode folder in main:all other codes (table sorts, jquery, ajax code, and getepisode.php)---All my includes are in the header of the index.php file.Perhaps its because I include browse.php which then includes the getepisode.php meaning the included js files dont reach it?

Link to comment
Share on other sites

  • 3 weeks later...

Kk, new issue and ive tried fixing it through given methods of including the javascript in the ajax response thing.Anyways, I want to now embedd a video using jw player embed.

<embedsrc="/jw/embed/player.swf"width="400"height="320"bgcolor="undefined"allowscriptaccess="always"allowfullscreen="true"flashvars="file=http://content.longtailvideo.com/videos/flvplayer.flv&dock=false"/>

That code works when I put it into my getepisode.php i guess cuz its jus like tables, doesnt need javascript or nething to work. But it makes me a bit uneasy for ppl to see the links i suppose so the other alternative was to do javascript embed.

<script type="text/javascript" src="http://www.jeroenwijering.com/embed/swfobject.js"></script> <div id="player">This text will be replaced</div> <script type="text/javascript">var so = new SWFObject('/jw/embed/player.swf','mpl','400','320','9');so.addParam('allowscriptaccess','always');so.addParam('allowfullscreen','true');so.addParam('flashvars','&file=http://content.longtailvideo.com/videos/flvplayer.flv&dock=false');so.write('player');</script>

Anyways, it doesnt work when put into the code and I also tried switchin up the javascript code to my selectepisode.js script. Any tips on correctly setting up this one?

Link to comment
Share on other sites

No no, lol, i mean, the javascript works fine when in any other page. But the call to the ajax page isnt registering it as a javascript embed. Just plain text like last time.I guess an even simpler question would be, should I even bother with the java script embed or will regular embed really be no different.

Link to comment
Share on other sites

Returning all of that code and trying to run it isn't the best thing to do. It would be better if the ajax response just sent the filename back, and you just use the filename in that code to embed it. I mean, there's no reason to return all of the code when the only thing you're looking for is the filename, might as well have the code be regular Javascript code and just send a request out to figure out which file to put there.Using SWFObject has advantages over using just a regular embed tag, but I'm not sure if the advantages matter much for your site.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...