I have a site with an flash player.
This codes servers me the flash player stored in player_codes.php:
<script language="javascript" type="text/javascript" src="songs_related/flashmp3player/swfobject.js" ></script>
<!-- Div that contains player. -->
<div id="player">
<h1>No flash player!</h1>
<p>It looks like you don't have flash player installed. <a href="http://www.macromedia.com/go/getflashplayer" >Click here</a> to go to Macromedia download page.</p>
</div>
<!-- Script that embeds player. -->
<script language="javascript" type="text/javascript">
var so = new SWFObject("songs_related/flashmp3player/flashmp3player.swf", "player", "290", "247", "9"); // Location of swf file. You can change player width and height here (using pixels or percents).
so.addParam("quality", "high");
so.addVariable("content_path","songs_related/uploads"); // Location of a folder with mp3 files (relative to php script).
so.addVariable("color_path","songs_related/flashmp3player/default.xml"); // Location of xml file with color settings.
so.addVariable("script_path","songs_related/flashmp3player/flashmp3player.php");
// Location of php script.
so.write("player");
</script>
This is how i include the player backend
<div id="main_music_player_for_the_site">
<?php include_once('player_codes.php'); ?>
</div>
If you go to this link here and press play on any song in the list the following happens:
I send a request to backend and set the song.
Confirmation comes to me.
I load the player from the player_codes.php (given above)
But when step 3 happens it refreshes! and gets stuck
It should not refersh its not refreshing in my localhost also.
Here is my JS that does the work (called after i get a response in step 2)
function callBackForLoadSong(data)
{
//alert(data);
if(data == "failed")
{
alert("Song requres you to login. Its easy to create an account! We will take you to the login page after you press ok");
window.location.replace(REDIRECT);
}
else
{
//alert("s");
$("#main_music_player_for_the_site").text("refreshing player...");
$("#main_music_player_for_the_site").load("player_codes.php");
}
}
Main thing thats bugging me is why is the page getting refreshed??? and getting stuck
You have the same HREF for every play buttons. Looks like your onClick event loads the songs?
You should have :
play
Instead of :
play
Right now, you tell javascript to load your song with the onClick event and you tell the browser to go to a different URL using HREF. javascript:void(0) will prevent the browser to execute the HREF.
Well the actual problem lied in my return value of false AFTER I EXECUTE MY CALL BACK!!!
Here is the corrected JS :
function callBackForLoadSong(data)
{
//alert(data);
if(data == "failed")
{
alert("Song requres you to login. Its easy to create an account! We will take you to the login page after you press ok");
window.location.replace(REDIRECT);
}
else
{
//alert("s");
$("#main_music_player_for_the_site").text("refreshing player...");
$("#main_music_player_for_the_site").load("player_codes.php");
}
return false;
}
so a return false; must be specified in the function also
Related
Now that my woes with running the big .sql file within PHP (Using a PHP session variable within a MySQL file run in PHP) are dealt with I want to display a loading bar (.gif) that I've made and a message displaying that the user data is being uploaded into the database because I don't want the user to think that their browser is not loading the page (since this process can take up to a couple of minutes depending on the file size).
<img src='includes/loadingbar.gif' width='128' height='15' alt=''/></p>
Uploading your school data into the database, please wait.
This process can take a while depending on your file size and connection.
Above is the image and the message I want to display while the query is running, but I can't seem to get past the white loading screen while it is updating the data. I've tried echo'ing the message after the query, before the query, as HTML code placed before and after the PHP command - but all I get is still this evil white screen. Every time the loading message doesn't show up until the query has finished (ironically), is there a way for it to show during the query in the format I'm currently using, or do I have to steer towards other programming languages? Many thanks!
EDIT:
I've tried to use a command before and after the php tags but it still doesn't operate until after the query has finished:
<div id="message" div align="center"><img src="includes/loadingbar.gif" width="128"
height="15" alt=""/>
<br />
Please wait while your school data is being uploaded into the database.
This can take a short while depending on your file size and connection.
</div>
<script type="text/javascript">
$(document).ready(function()
{$('message').show(); });
</script>
<?php
session_start();
$page_title = 'SQLTest';
include ('includes/header.html');
require ('mldb_connect.php');
(etc...)
and at the end:
if ($populateresult)
{
$replace = $_SESSION['path'].$_SESSION['CentreNo'].'_'.$_SESSION['School'].'_'
.date('dmY_His').'.txt' ;
rename ($path, $replace) ;
}
?>
<script type="text/javascript">
$(window).load(function()
{$('message').hide();});
</script>
What am I doing wrong with this?
With jQuery you could do something like this:
$("#imgId").show(); // Show loading image.
Execute PHP script:
$.post( "your_script.php", function( data ) {
// $("#imgId").hide(); // Hide loading image.
window.location = "http://www.example.com"; // Redirect to URL.
});
Update: imgId being the id of your image. For instance:
<img src="image.png" id="imgId" />
I can tell you two different solutions.
Sol 1. When the query is firing as the page is loading: (with out Ajax):
In this case you can use some jquery.
$(document).ready(function(){
$('img').show();
});
$(window).load(function(){
$('img').hide();
});
This will ensure that when all the elements of the page are loaded only when the loader image hides.
sol 2.
if you want to do it via Ajax. Show the image when the event is fired that triggers Ajax, then upon the .success() or the .done() of the Ajax hide the image loader.
Though this is an old question, but it can be done without javascript.
need 'sessions_start()'.
forward to a page with please wait dialog and in the head section forwarder <meta http-equiv="refresh" content="1; url= http://example.com/myPage.php"
I am trying to load a static street view image, where the various parameters are stored in a mysql database. After trying lots of alternatives, I'm now passing the database data to a javascript variable and then trying to build the relevant URL (taking into account the page width along the way).
The page loads as restaurant.php?r=xyz where xyz is looked up on MySQL to return a line of data $r that is passed into a javascript array. Some of the array fields are used to create the URL of a Google Street view static image, which should then be loaded into the page.
This works fine if I enter the get to this page having started elsewhere on the site (or after a page refresh).
But if I start from this page and navigate around all future links to restaurant.php?r=abc do not load the image (it is downloaded and can be seen in the Chrome sources box). The pageinit event fires but the .html() fails to change the content (but reports no error).
I suspect I am breaking several laws of javascript, and jquery mobile....
Declared in header
var resto = {};
function insertSVPhoto() {
console.log("insertSVPhoto: Loaded data for: "+resto['rname']);
if ( Math.round(resto['heading']) != 0) {
var width = Math.round( $(document).width() * .9);
var s= "x250&location="+resto['lat']+",%20"+resto['lng']+"&fov=60&heading="+resto['heading']+"&pitch="+resto['pitch']+"&sensor=false";
var photo = "<img src='http://maps.googleapis.com/maps/api/streetview?size="+width+s+"'>";
console.log("Loading photo: "+photo);
$('#svphoto').html(photo);
} else {
console.log('No photo available');
$('#svphoto').html("<img src=''>");
}
}
And then below I have
<div data-role="page" data-add-back-btn="true">
<script type="text/javascript" >
<?php
echo "resto = ".json_encode($r).";";
?>
$( document ).on("pageinit", insertSVPhoto );
</script>
<div id='svphoto'></div>
I have to confess i'm no expert here but the way you're doing this doesn't seem quite right to me, i'd do the following:
window.onload = function () {
if(! window.device)
deviceReady()
}
document.addEventListener("deviceReady", deviceReady, false);
function deviceReady() {
$(document).delegate('#YOUR_PAGE_ID', 'pageshow', function () {
// Add your stuff here for doing the photo....
}
Again I only started using JQM a while ago but I know this works for an app i've done(and for a phonegap build too!)
EDIT: Also I would seriously consider putting everything all in one HTML document the way you've developed this is going to cause you a massive nose bleed if you try and build this as a mobile app, JQM is not designed to be used in the same way as Jquery, all of your "pages" should exist in one single html document and then use the navigation functions to move between pages.
Thanks
Marc
add data-ajax="false" or rel="external" to your links.. that should make it load properly
hello
OR
hello
I want to execute a php code when a user click on a given link , i've tried the following code
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
$.get("up.php");
return false;
}
</script>
</head>
<body>
<center>
Click Me!
</center>
</body>
</html>
where up.php is a php code that implement android GCM mechanism similer to the one in the link : GCM with PHP (Google Cloud Messaging)
but unfortunately when the link is clicked nothing happens , the php code not executed ,and only the url of the page change form *****.com/test.html to *****.com/test.html# , and by the way I've tested the php code and its works fine so it is not a problem in php code , so what i have missed here? why the code is not executed?
i found the solution , the problem that the jquery library is not included probably in my code
you are using jquery. $.get() will be something like below.
$.get('ajax/test.html', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
for further help check http://api.jquery.com/jQuery.get/
Sometimes, you may need to call some JavaScript from within a link. Normally, when user click on a link, the browser loads a new page (or refreshes the same page).
This might not always be desirable. For example, you might only want to dynamically update a form field when the user clicks a link.
To prevent the load from refreshing, you could use the JavaScript void() function and pass a parameter of 0 (zero) as below.
<a href="JavaScript:void(0);" onclick="return doSomething(); " />Click Me!</a>
Now if you want to use href="#", make sure onclick always contains return false; at the end.
OR
Use href="javascript:void(0)"
You can also use jQuery Load
function doSomething() {
$('#result').load('up.php', function() {
alert('Load was performed.');
});
}
When you are using Jquery should be :
function doSomething(){
$.get('up.php', function(data) {
$('.data').html(data);
});
}
Link
To stop page refreshing, you can use the javascript void() function and pass parameter of 0.
Click Me!
<div class="data"></div>
This div is used to display up.php result.
Ok start of by using fire bug and watch the console and network panels
Ensure the browser is trying to get something and not returning a 404 or a php error on the get
Look into prevent default http://api.jquery.com/event.preventDefault/
To stop the original link functionality working
If you still want them to move to the link use a window location or...
Look into bootstrap link buttons
http://twitter.github.com/bootstrap/base-css.html#buttons
( the link button )
I have recently installed Simple Mailing List 2 (currently in beta) and I have got everything to work so far. The main thing that was left for me to do was to make a custom php page which the signup form redirects to once submitted. The content that the page shows is based on what the user enters in the email field and returns one of three results:
an error message if the email syntax is incorrect.
a custom message if the user has subscribed telling them to check their email.
a custom message if the user has chosen to unsubscribe.
That's the background out of the way. Now what I intend to do is show a popup window that includes the contents of the redirected php page (ie. one of the three results) instead of going to a new page. Is it possible to do this a css popup box so I don't have to open up a new window?
Thankyou
Adam
You can use JavaScript to send an ajax request to the PHP page that will do the calculations, the result will then be sent to your "window" content and then you show the window to the user
You're mixing metaphors. CSS is just a presentational technology that you use to determine the style of something. There is no such thing as a "css popup box".
What you want to do is have an HTML element (likely a div) that contains the information you intend to show, initially set to not be visible (you use CSS for this with the display:none; style). What you're describing is essentially an AJAX interaction that uses Javascript to parse the contents of the form, send data to the server to be evaluated, and return a message to be displayed (without triggering a postback/going to a new page). That Javascript would also handle the CSS part of setting the display of the HTML element to true.
This is a fairly common scenario, so you should be able to find snippets online.
...but here's a super dumb example
<html>
<head>
<title>AJAX Test</title>
</head>
<body>
<form action="#">
<input type="text" id="enterStuff" />
</form>
<div id="response" style="display:none;">
<p id="message">Put stuff in me</p>
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
registerEventListeners();
});
function registerEventListeners(){
jQuery("#enterStuff").change(getData);
}
function getData(){
jQuery.ajax({
type : 'POST',
data : {
stuff : jQuery("#enterStuff").val(),
},
url : "http://localhost/myprocessor.php",
success : showCool,
complete : updateDisplay
});
}
function showCool(data, textStatus, jqXHR){
var selector = jQuery("#message");
selector.val(data)
}
function updateDisplay() {
jQuery("#response").show();
}
</script>
</body>
</html>
Then your myProcessor.php would have to read the value of the variable, do some logic, and echo a response.
You could use an <iframe> as an in-document 'pop-up', you just set the target of the form to the name/id of the iframe. (You can use some JavaScript to only show the iframe once the form is submitted.)
okay so on my home page i'm doing a user name and password check and then im using jquery document.location to send you to a logged in page say secure.php.... while this works it sends you to secure.php first and then images start loading ... how can i do it in such a way that it loads the entire page and then send you to secure.php
example : -
$.ajax ({
url: loginCheck.php,
type: 'POST',
data: username + password ,
success: function (check){
if(check==1)
document.location= /loginpage/secure.php
else alert(invalid username or pass)
}
});
Edit: I'm replacing my entire question now that I understand what you are trying to do. In secure.php, put all of your code in a containing div, something like this:
<body>
<div id="contentContainer">
<!-- content goes here -->
</div>
</body>
Set a style for #contentContainer to be hidden:
#contentContainer {
display: none;
}
Add a window.onload handler to show the div. Unlike onready, onload isn't called until all of the content has loaded including images.
$(window).load(function() {
$("#contentContainer").show();
});
You may want to do the same thing in reverse to a "loading" div with a message that says "loading...". Ie, initially display it, and hide it in the onload handler.
Edit: You can speed up the loading of the page by pre-loading the images in a hidden div in the previous page.
Home.php
<div class="preloader">
<img src="..." />
...
</div>
.preloader {
display: none;
}
Secure.php should load using the cached images.
...this strikes me as highly unsecure, but oh well.
Unless you build a metaframework in jQuery where all page loads are performed in a "shell" and then displayed only when ready to render, the answer is, I'm pretty sure, you can't.
Pages have a definite life cycle. jQuery and AJAX kinda blur the line a bit, but a page load is a singular event that controls the scripts. Loading the page would make the script you were using to load the page go away.