$(document).ready(function() isn't called - php

I've set document.ready in the middle of a page.
It was working fine on local server, on an online production beta server, but failed on the final server.
Any suggestions?
thx
Code:
$(document).ready(function() {
And yes. JQuery is loading and it's working propely
UPDATE: These days I've found the same issue and for futher reference the script tag that includes the jQuery must be propely closed. If not the $(document).ready() is never called.
Wrong:
<script type='text/javascript' src='js/jquery-1.6.2.min.js'/>
Also wrong:
<script type='text/javascript' src='js/jquery-1.6.2.min.js'>
Right:
<script type='text/javascript' src='js/jquery-1.6.2.min.js'></script>
Nowadays using hmtl5 <!DOCTYPE html>

Get Firebug and check:
is jQuery loading or is it missing. And is it loaded before the document.ready ?
is the script throwing any JavaScript-errors?

The most likely problem is the production server doesn't have a copy of jquery. Switching to having google provide jquery for you is a good practice.

Related

php Ajax calls fails on one server

I copied a script that works on one server to another but it doesn't work on that server. To troubleshoot it I created a test file with just this code
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script>
ShowThePopout();
function ShowThePopout() {
console.log('show box');
$.post( "sidebox_ajax_test.php", { show_cart: true })
.done(function( data ) {
console.log('good result');
});
}
</script>
The sidebox_ajax_test.php file just has this
<?php
echo 'done';
I uploaded the two files to both servers. When the test page is visited, on the first server the console shows
show box
XHRPOSThttp:.../sidebox_ajax_test.php
good result
On the second server it shows
show box
No errors are thrown, that I can see. Both accounts on the servers are using php 7.4. I saw many posts about a similar problem that said CORS needs to be enabled and it is on both servers. Any ideas on how to fix this or what to try?
Problem solved. I tried using Chrome instead of FF and its console reported a problem loading jquery due to the link not being secure. Changed that and it worked.

jQuery clax not working where I add jQuery min.js

When I use jQuery clix then ajax is not working after when I use jQuery latest version then jQuery clix not work.
<script src="{{asset('build/js/custom.min.js')}}"></script>
<script src="{{asset('js/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('js/jquery-calx-sample-2.2.8.min.js')}}" type="text/javascript"></script>
j query calx actually not work latest jquery.min,js, if you use old less than 2 version that can do work. use this cdn i think solve your problem.
or if you face as like-enter code here jQuery tooltip and popover not load and work
you can try this jquery code:-
$('.hasTooltip').tooltip();
or say more details your actual problem.

Is it possible to make Iframe alternate?

My problem:
I can display content of a php file including(image background) using iframe. When I go to include my php file using
include("modules/form.php");
or
file_get_contents("modules/form.php");
it displays content, but background image becomes invisible. It is a big site. So, is there any alternate of iframe for this purpose? I do not want to use iframe because my ranking in google is becoming down.
You can't archive this using php , till far i know. PHP is a server side script it does not know anything from the client side. You can use jquery , first you will have to create a div and in it set the content of the page.Use the code below
<head>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=1.4'></script>
<script type='text/javascript'>
$(document).ready(function (){
$('#divId').load(full url to modules/form.php); // Paste the full url here
});
</script>
</head>
<body>
<div id="divId"></div>
</body>
</html>
Hope this helps you

php error on joomla site

We have two instances running of a joomla hosted site. One is on test server while the other one is on live server.
We are getting one issue where on the test server, site is displaying correctly but not on live server.
We zeroed on one particular line in the page source view, here is the difference of one function from both test as well as live server
test server
<script language="javascript">
$(document).ready(
function (){
$(".pikame403").PikaChoose();
});
</script>
live server
<script language="javascript">
$(document).ready(
function (){
$(".pikame<?=$list['id']?>").PikaChoose();
});
</script>
to me it looks like on the live server, php is not concatinating the id. Any hints/suggestions are welcome. Also it would be nice if someone could indicate where the addins are store their code.
Not all servers allow to use short tags <?= for echoing. On your test server short tags switched on, on production -- switched off, so they don't work.
You can solve your problem in 2 ways:
Switch on short tags on production server.
Do not use short tags (which I strongly recommend). Just change your code <?=$list['id']?> to <?php echo $list['id']; ?>.

Wordpress: Jquery works inline, NOT on an external file

my problem is quite annoying and weird. I have created a custom Wordpress theme and in the header.php I was loading jquery like this (can't remember why right now):
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript"> google.load("jquery", "1"); </script>
Last night I replaced the code above with
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
and then my site collapsed. I changed it immediately back again, but the problem persisted. I placed some Jquery in the HTML and it works just fine. Then I disabled my plugins by commenting out code in my functions.php file as below:
<?php
if (!is_admin()) {
wp_register_script('custom', get_stylesheet_directory_uri().'/js/custom.js');
wp_enqueue_script('custom');
wp_register_script('blockui',get_stylesheet_directory_uri().'/js/jquery.blockUI.js');
wp_enqueue_script('blockui');
wp_register_script('fancy',get_stylesheet_directory_uri().'/js/jquery.fancybox.js');
wp_enqueue_script('fancy');
wp_register_script('jeasing',get_stylesheet_directory_uri().'/js/jquery.easing.js');
wp_enqueue_script('jeasing');
wp_register_script('friendchooser',get_stylesheet_directory_uri().'/js/jquery.friendChooser.js');
wp_enqueue_script('friendchooser');
wp_register_script('zclip', get_stylesheet_directory_uri().'/js/jquery.zclip.min.js');
wp_enqueue_script('zclip');
}
?>
Still the problem occurs. Any ideas?
There is syntax error in custom.js file in line 30. Just remove } from there.
And learn some about firebug, it's very helpful :)

Categories