Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Page not loading correctly via jQuery .load()

Posted on 2016-10-04
5
Medium Priority
?
169 Views
Last Modified: 2016-10-07
Source page is prelist_plan_levels.html, (see attached).
The link in source page:
<a href="/cmdb/public_html/Work/list_plan_levels.html" class="UpDowngrade" data-target="center_body" data-pp="Nov 2015" data-scope="PP" data-updown="UP">25</a>

Open in new window

NOTE that there are 3 of these links in the page, each with different 'data-key="value"' parameters, ALL containing data-target.

Source page .ready() function is review_plan_levels(), containing event catcher
$('body').one( "click", 'a.UpDowngrade', listPlanLevelsClick ) ;

Open in new window

Destination page list_plan_levels.html, (see attached).

JS listPlanLevelsClick() function is also attached.

ISSUES:
I've tried two variations of function listPlanLevelsClick(event), the one shows unsuccessfully tries to rely on 'data-target="blah"', but the page does not load in the designated DIV in my web app.  It loads in the entire window.  (See also index.html.)
When it does load, it will correctly perform the commented-out .DataTable() load.

The other variation of this function is to use the commented-out code to force loading into the DIV I desire.
It does target correctly then, but:
A) The success callback never alerts me (an issue?)
B) More importantly, even with a minimal DataTable() configuration, in the console I'm seeing
Uncaught TypeError: $(...).DataTable is not a function

Open in new window


All the cdn.datatables.net  JS and CSS links were fresh as of last week.  Again, it does load a table w/ data when it incorrectly places it in the entire window.

Add'l confusion but not an issue:
Also, you'll note that I'm using  
$('body').one( "click", 'a.UpDowngrade', listPlanLevelsClick ) ;

Open in new window

rather than .on(), because for some reason, maybe you'll understand why, each failed load (when correctly targeted) would retain the click, because subsequent clicks would repeatedly call listPlanLevelsClick(), once for every prior click.

See also http://plnkr.co/edit/oyaHJhYFT8hrz0UcKPR0?p=preview.  That may help, I believe it's public.

Thank you,
Ralph
prelist_plan_levels.html
list_plan_levels.html
list_plan_levels--.txt
listPlanLevelsClick--.txt
index.html
0
Comment
Question by:Ralph
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Assisted Solution

by:Kim Walker
Kim Walker earned 1000 total points
ID: 41829137
These <a> elements are contradictory. They should navigate to the url /cmdb/public_html/Work/list_plan_levels.html when clicked. However, you've attached a click event that attempts to execute a javascript function. I imagine the href navigation will overpower the javascript function execution. Which do you want to happen, navigate to the href url or execute the click event javascript?
0
 

Author Comment

by:Ralph
ID: 41830681
Hi,

I need the data from the link to provide parameters for the AJAX operation once it get to the target page list_plan_levels.html, and using that page's .ready() function to run list_plan_levels().

Is there another way to get the link-embedded data-key="value" data to the .ready() function for /cmdb/public_html/Work/list_plan_levels.html?

Thank you.
0
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 1000 total points
ID: 41831228
Is there another way to get the link-embedded data-key="value" data to the .ready() function for /cmdb/public_html/Work/list_plan_levels.html?

Are you asking if
<a href="/cmdb/public_html/Work/list_plan_levels.html" data-key="somevalue" />
When clicked takes you to the list_plan_levels.html page
Are you asking if there is a way that the data-key value somevalue can be passed to that page
Answer: as a url paramater
/cmdb/public_html/Work/list_plan_levels.html?key=somevalue
You can then retrieve that value in the page with
var search = window.location.search.substring(1);
var params = search.split('&');
var result = {};
for(var i=0;i<params.length;i++) {
	var keyvalue = params[i].split('=');
	result[keyvalue[0]]=keyvalue[1]
}
console.log(result.key);

Open in new window

0
 

Author Closing Comment

by:Ralph
ID: 41832812
Cool, cool, COOL!

VERY frustrated that I couldn't get a rather simple link to target correctly, or get the targeting right but couldn't get to the destination page w/o errors.  I hope I don't have to face that mystery again.

If this works I'm moving again, after a week of frustration and dozens of failed approaches to troubleshoot.

Thanks!
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41833119
You are welcome.
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question