Solved

Page not loading correctly via jQuery .load()

Posted on 2016-10-04
5
69 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
  • 2
  • 2
5 Comments
 
LVL 21

Assisted Solution

by:Kim Walker
Kim Walker earned 250 total points
Comment Utility
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
Comment Utility
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 51

Accepted Solution

by:
Julian Hansen earned 250 total points
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
You are welcome.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now