jQuery Get for PHP files - php

I have this statement in my jQuery file:
$.get("homeTemplates/randomVids.php", function(data){$("#hVid").html(data);});
Where the contents of randomVids.php should be loaded into a div called hVid. However, this does not work for me: nothing seems to load when the line is executed.
I consulted this page for information.
Any help would be appreciated.

You should probably just use this...
$("#hVid").load("homeTemplates/randomVids.php");

Related

Using "include" to put CSS into PHP file

I've looked at other questions/answers on this and none have seemed to work for me.
I have a PHP file that is loaded via AJAX. In that I have...
include('mods/math/include/geometry_styles.php');
The geometry_styles.php file basically looks like this...
<style>
.proof_ol_outdent {
position: relative;
margin-left: -18px;
}
</style>
The .proof_ol_outdent style is not getting recognized by Firebug (or used, for that matter). I also don't seem to get any PHP errors if I mess with the path of the include(), which seems strange. If I change the include to require though, everything breaks.
However, I think that my path is correct because I have a DEFINES file which I also load using include and it's path is include('mods/math/include/geometry_defines.php');. The defines get loaded and used properly using that path.
I have no idea why this isn't working. Any help would be appreciated.
UPDATE: To answer a couple comment questions....
1.) AJAX is loading table rows that fit into <tbody id="problem_area"> </tbody>.
2.) There is a file called ajax_loading.php which loads the content of a user-specified file by id number. Like this: ajax_loading.php?problem_id=34
3.) If I browse directly to ajax_loading.php?problem_id=34 I don't get the <style></style> tags should be present.
I've found an alternate way to get my CSS included. Therefore I'm closing this thread. My feeling is that since the data is being loaded via AJAX, that's causing some kind of problem. I don't know for sure though.
Thanks to all who commented and tried to help.

Isotope not responding to class name

I have a class that works with isotope.
The trigger class is loaded through jquery from a PHP file and is therefore not loaded right away.
I can see the class in the DOM, but not in the source code.
Should this stop it from working all together?
I am not sure what code I can post in relation to this, because it is a huge project and the content of the php loads fine through the jquery call, but the isotope does not work when I do it this way.
To clarify if I load it in the html file directly, the isotope works. So that is confirmed.
It only stops working when it loaded from the PHP file, however it is still displaying all the divs.
Any ideas?
========
added binding code
<li>All</li>
<li>Chair</li>
<li>Secretary</li>
<li>Treasurer</li>
<li>Admin</li>
Thanks :-)
It works now
I had to change
$('#menu-items').html(msg);
into this:
$('#menu-items').html(msg);
$('#menu-items').isotope('reloadItems');

custom php function to call in header

I have a Wordpress website. I am asking for help as I am not good with codes, but know a bit about the flow of functions and all.
I want to add a new PHP function that will be defined in a separate file. The function to be defined is required to serve a 728x90 banner ad on top of the header area of the site (so I guess the php function will also have CSS styling to align the ad in the center). I don't know what I am saying will be possible the way I am saying.
Alternatively, there might be a way to call a js function defined in separate file, then called in the php header to serve the banner (again center-aligned).
I am seeking help here as Stackoverflow also helped me solve problems previously.
Is there anyone who can help me get this thing done?
Once you have your PHP handler written in a separate file call it using require_once like this:
<?php
require_once('myfile.php');
// Wordpress Stuff
?>
I guess PHP have no relation with CSS/styling, you can do it with Javascript.
like this or using JQuery

AJAX, PHP Copied Files not Found on Return to Browser

I am using 'jQuery AJAX PHP' to do some '.jpg' file copying (approx 330kb per file). I copy files to a new directory location.
When I return to the HTML and use jQuery to add an IMG tag to a Table element, some of the files I have copied are shown as Not Found with 404 errors, but they are there.
I am wondering if it is a speed error. I tried to slow down the return from the PHP, by reading the directory where the files had been copied to, but that did not seem to help.
Am I right in thinking it is a speed problem and does anyone have an idea as to how I may overcome this problem, because only by displaying the copied file, can I be certain it has been copied.
Sometimes I have the same problem with not loading the images. If you are going to use jQuery I will recommend that you put your script (which loads the images) in
$(document).ready(function() {
// put all your jQuery goodness in here.
});
The fact is that your DOM object is not ready when you want to show or make operation with it.
Don't forget to call
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
in the head of your HTML.
Having tried various options suggested here and some others, I researched, I decided to try putting the display of the images in a different function from the AJAX/PHP. In other words instead of processing the images in the result function of the AJAX call, I just passed the results from the success function to another function.
This seems to have cured my not-found displays.
This may be a coincidence, with something else going on, because I am very poor in the knowledge of the flow of the DOM.

Can PHP be inserted into a javascript call in my header?

I have a wordpress theme that I like to duplicate. To make things easier on myself, I'm trying to use the bloginfo function to call my jquery file..like this:
<script type="text/javascript" src="<?php echo bloginfo("template_url"); ?>/js/jquery-1.4.2.min.js"></script>
I just can't get it to work. When I check my source file it looks exactly like the code above.
Can this even be done, or should I just forget it? Thanks guys!
Are you sure the above code is actually in a PHP-file and gets parsed by the server? I can't think of a different reason why PHP-code should just be printed and not executed.
See the Referencing Files From a Template chapter in http://codex.wordpress.org/Theme_Development
Whats the name of this file? It should end in .php.
What does the source look like when you view it from the browser?
Are there other places in the file where you use and is that data correct?
Make sure there are no blank lines at the end of the source file. PHP doesn't like blanks lines at the end of the code.
Two problems: No need for the echo in the WP template tag; should be
<?php bloginfo("template_url"); ?>
Template Tags/info « WordPress Codex
And, why are you trying to include jQuery from the template directory, when it resides in wp-includes/js? You should be using Function Reference/wp enqueue script, if your theme doesn't already include jQuery.
You should try to edit your theme's header.php file directly because custom fields of your theme may not be executed by PHP interpreter.
As I've never used PHP, this is only a guess...
PHP is a server side language, and you're tyring to use it on the client side?

Categories