• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Page not loading correctly via jQuery .load()

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
Ralph
Asked:
Ralph
  • 2
  • 2
2 Solutions
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
RalphAuthor Commented:
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
 
Julian HansenCommented:
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
 
RalphAuthor Commented:
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
 
Julian HansenCommented:
You are welcome.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now