- Screen name: Laura11111307048678
Laura11111307048678's Profile
3 Posts
11 Responses
0
Followers
Show:
- Expanded view
- List view
Private Message
- 17-Sep-2017 10:42 AM
- Forum: Using jQuery
I have written a widget and it works great, but right now I am giving my users a link to a remote script,
a link to my script and a div to place on their page. I would like to reduce this to just a link to my script
and the div. The remote link I want to include in my code below is<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Can anyone please educate me on how and where to add this link to jquery-ui.js link in my code? I already link to a remote jquery and a remote stylesheet, but I am not sure how/where to include another remote link. I have tried a number of places and ways, but I keep breaking my page, haha. The code before is working for me, just need to figure out how to include that last link in the code... Thanks for any help offered.
- (function() {
- // Localize jQuery variable
- var jQuery;
- /******** Load jQuery if not present *********/
- if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.12.4') {
- var script_tag = document.createElement('script');
- script_tag.setAttribute("type", "text/javascript");
- script_tag.setAttribute("src", "//code.jquery.com/jquery-1.12.4.js");
- if (script_tag.readyState) {
- script_tag.onreadystatechange = function() { // For old versions of IE
- if (this.readyState == 'complete' || this.readyState == 'loaded') {
- scriptLoadHandler();
- }
- };
- } else {
- script_tag.onload = scriptLoadHandler;
- }
- // Try to find the head, otherwise default to the documentElement
- (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
- } else {
- // The jQuery version on the window is the one we want to use
- jQuery = window.jQuery;
- main();
- }
- /******** Called once jQuery has loaded ******/
- function scriptLoadHandler() {
- // Restore $ and window.jQuery to their previous values and store the
- // new jQuery in our local jQuery variable
- jQuery = window.jQuery.noConflict(true);
- // Call our main function
- main();
- }
- /******** Our main function ********/
- function main() {
- jQuery(document).ready(function($) {
- /******* Load CSS *******/
- var css_link = $("<link>", {
- rel: "stylesheet",
- type: "text/css",
- href: "//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"
- });
- css_link.appendTo('head');
- /******* Load HTML *******/
- var jsonURL = "//www.myurl.com/mssql.php/ws_nfy";
- jQuery(document).ready(function() {
- jQuery.ajax({
- url: jsonURL,
- success: searchCallback
- });
- });
- function searchCallback(data) {
- var ws_nfy = data.ws_nfy.records;
- jQuery.each(ws_nfy, function(index, nfy) {
- jQuery("#tabs ul").append('<li><a href="#tabs-' + nfy[0] + '">' + nfy[2] + '</a></li>');
- jQuery("#tabs ul").after("<div id='tabs-" + nfy[0] + "'>" + nfy[1] + "</div>");
- });
- $("#tabs").tabs();
- };
- });
- }
- })(); // We call our anonymous function immediately
- I built this same tabbed system using PHP and it works great, now I am trying to get it to work as Jquery and am *almost* there!
I am trying to load my well-formatted JSON data into a tabbed structure. So far the data is in and showing up where it should. My problem is that the style is being dropped from the li element and I believe it is because of how I set up my javascript in the JQuery.each section. Does anyone have any idea how I can fix this? Here is the function I use to callback the data:function searchCallback(data) {
var content_data = data.content_data.records;
jQuery.each(content_data, function(index, content_dat) { jQuery("#tabs ul").append('<li><a href="#tabs-'+
content_dat[0]+'">' + content_dat[2] + '</a></li>'); jQuery("#tabs ul").after("<div id='tabs-"+
content_dat[0]+"'>"+content_dat[1]+"</div>"); }); }; </script> <div id="tabs"><ul></ul> </div>
The div id="tabs" becomes div id="tabs" class="ui-tabs ui-corner-all ui-widget ui-widget-content" just like it is supposed to...
and the ul becomes ul class="ui-tabs-nav ui-corner-all ui-helper-reset ui-helper-clearfix ui-widget-header" role="tablist" just like it is supposed to...
but the li remains li and does not pick up the class it is supposed to...
I am thinking this may have something to do with the way Jquery is appending to the #tabs ul so the li is not available for transforming, but I am not sure...
- I am new to JQuery and need some help understanding how to structure my code... I have a working JSON page and have been able to get my code to display the intended results. Now I want to put those results in a tabbed format. Basically the title of my article is in the tab and the body of the article underneath. My code right now shows all of the titles in the tabbed area up top, which is correct, now I need to get the body in the main part. The final structure should look like this:
- <div id="tabs">
<ul>
<li><a href="#tabs-1">AAA</a></li>
<li><a href="#tabs-2">BBB</a></li>
<li><a href="#tabs-3">CCC</a></li>
</ul>
<div id="tabs-1"><h2>AAA</h2><p>This article is about AAA</p></div>
<div id="tabs-2"><h2>BBB</h2><p>This article is about BBB</p></div>
<div id="tabs-3"><h2>CCC</h2><p>This article is about CCC</p></div>
</div>
- var jsonURL = "//www.myurl.com/api.php/content_data?columns=id_cr,title,teaser&order=title&page=1";
jQuery(document).ready(function() {
jQuery.ajax({
url: jsonURL,
success: searchCallback
});
});
function searchCallback(data) {
var content_data = data.content_data.records;
jQuery.each(content_data, function(index, content_dat) {
jQuery(".tabs").append('<li><a href="#tabs-' + content_dat[0] + '">' + content_dat[2] + '</a></li>');
});
};
</script>
<div id="tabs">
<ul>
<div class="tabs"></div>
</ul>
<div class="body"></div>
</div>
content_data columns 0 "id_cr" 1 "teaser" 2 "title" records 0 0 69425 1 "<p>Hurricane Harvey has been one of the strongest weather storms to hit the U.S. this year and has caused severe flooding in Texas and parts of Louisiana.</p>" 2 "Hurricane Harvey Aftermath" results 1
- «Prev
- Next »
- <div id="tabs">
Moderate user : Laura11111307048678
© 2013 jQuery Foundation
Sponsored by and others.

