3

I'm struggling on this question for whole day, so maybe someone could help.

I want to load settings.php page, which includes javascript/jquery code with usual html, into index.php on button click.

Here are the code snippets:

Index.php

<head>
<script type="text/javascript">
        function loadSettingsPage (){
        $('#myResults').load('settings.php', function (){ });
        }
</script>
</head>

Settings.php

<div class="tabsWrapper">
<ul class="tabs">
    <li data="sections" onclick="setTab('sections')">Product categories</li>
    <li data="suppliers" onclick="setTab('suppliers')">Suppliers</li>
</ul>
</div>
...
<script type="text/javascript">
function setTab(currentTab = "sections"){
//some code goes here
};

$(document).ready(function (){
//document ready code goes here with click events
}
</script>

The question is, how to load/include Settings.php file into index.php file so that all javascript code included click events in $(document).ready function is executed in safari browser as well. Now it works perfectly with all browsers but safari.

2
  • Could you just include('settings.php') inside of your HTML myResults element. Commented Aug 25, 2016 at 20:21
  • Not an option, I want to load settings.php dynamically. I could load it, hide and then onclick appear, but I have bunch of other files which should be included/removed into myResults div according to click. Commented Aug 25, 2016 at 20:34

1 Answer 1

6

You're trying to use the EcmaScript 6 feature of default parameters. This isn't yet implemented in Safari, Opera, or Internet Explorer, according to MDN.

Use an explicit check for whether the argument is set:

function setTab(currentTab) {
    currentTab = currentTab || "sections";
    // some code goes here
}

You need to be very careful about using new ES6 features, many of them are not yet implemented in Safari, and they'll never be implemented in old IE versions.

Sign up to request clarification or add additional context in comments.

6 Comments

I was writing the same answer just not as good, quickly hit the delete button plus 1.
Okay, I will fix this, but the main problem is still alive
This seems like the main problem to me. You were getting a syntax error, so the code didn't run. Are you still getting errors? What does it say in the Javascript console?
OMG I get tones of errors and warnings, it will take lots of time to fix them all (( Why does safari behave so stupidly and different way from all other browsers
You should probably bookmark caniuse.com to see what features are incompatible between browsers.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.