I'm trying to load a page when a div from my content is loaded , but isn't working. Can you help me and tell me where is my error or why isn't working ? Thanks !
Here's the code
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/fonts.css" rel="stylesheet" type="text/css" />
</head>
<body>
<ul id="nav">
<li>index</li>
<li>contact</li>
</ul>
<div id="content"></div>
<script src="http://code.jquery.com/jquery-2.0.2.min.js" type="text/javascript"></script>
<script src="js/js.js" type="text/javascript"></script>
</body>
</html>
hello.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
And javascript
$(document).ready(function() {
$('#content').load('hello.php');
});
Use this in head section
<script src="http://code.jquery.com/jquery-2.0.2.min.js" type="text/javascript"></script>
<script src="js/js.js" type="text/javascript"></script>
Change your html like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/fonts.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-2.0.2.min.js" type="text/javascript"></script>
<script src="js/js.js" type="text/javascript"></script>
</head>
<body>
<ul id="nav">
<li>index</li>
<li>contact</li>
</ul>
<div id="content"></div>
</body>
</html>
And your Jquery like th is:
$("#content").load("/hello.php", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#error").html(msg + xhr.status + " " + xhr.statusText);
}
});
This should work, and if not it will let you know what happened.
You have to make sure this script tag
<script src="http://code.jquery.com/jquery-2.0.2.min.js" type="text/javascript"></script>
is executed before
$(document).ready(function() {
$('#content').load('hello.php');
});
Related
Title tag displayed as "untitled document" for a file(apparel.php) which is in a folder(fashion) but appears correctly for a file(login.php) which is not in a subfolder.
Here is the head section of apparel.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Apparel</title>
<meta name="viewport" content="width=device-width, maximum-scale=1.0,
initial-scale=1.0", user-scalable="yes" />
<link rel="stylesheet" type="text/css" href="../css/main.css" />
<link rel="stylesheet" type="text/css" href="../bootstrap-3.3.7/css
/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/navbar.css" />
<script src="../js/navbar.js"></script>
<script type="text/javascript" src="../js/jquery-3.3.1.min.js">
</script>
<script src="../bootstrap-3.3.7/js/bootstrap.min.js"></script>
</head>
Here is the head section of login.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login </title>
<meta name="viewport" content="width=device-width, maximum-scale=1.0,
initial-scale=1.0", user-scalable="yes" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7/css
/bootstrap.min.css">
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script src="bootstrap-3.3.7/js/bootstrap.min.js"></script>
</head>
Any help is really appreciated.
I have a PHP function that displays an error message as part of form validation, I have mixed in some HTML to create a page for it;
function displayMessage($msg)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
<title>Error sending message</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div style="box-sizing: border-box; width:100%;font-family:arial;font-size:16px;color:#333333;background:#ffe6e3;padding:10px;background:#ffe6e3;border:1px solid #fb8d8d;">
<?php return $msg; ?>
</div>
</body>
</html>
<?php
}
When the code is run everything looks right in the browser, however, looking at the source code it stops right after the message is displayed so the closing div, body, and html tags are not shown.
How do I get them to show, I have tried echo instead of return but that displays the error message but still processes the form.
You are using functions incorrectly, (similar to a require_once). Functions are meant to be called and return a value, not used to include dynamic code in this manner. The reason why it stops after return $msg is because you are telling the function to return a variable called $msg and end further execution of the function block.
I'd suggest using something like this
function displayMessage($msg)
{
$html = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
<title>Error sending message</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div style="box-sizing: border-box; width:100%;font-family:arial;font-size:16px;color:#333333;background:#ffe6e3;padding:10px;background:#ffe6e3;border:1px solid #fb8d8d;">
$msg;
</div>
</body>
</html>
EOD;
return $html;
}
echo displayMessage($msg);
return from a function means instantly going back to whoever called it. Means none of the lines below return will be executed.
Change the below:
<?php return $msg; ?>
To:
<?php echo $msg; ?>
The return keyword should be used only inside a function call.
return means "return this value from the function, and stop executing the function". The keyword that you're actually looking for is echo:
function displayMessage($msg)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
<title>Error sending message</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div style="box-sizing: border-box; width:100%;font-family:arial;font-size:16px;color:#333333;background:#ffe6e3;padding:10px;background:#ffe6e3;border:1px solid #fb8d8d;">
<?php echo $msg; ?>
</div>
</body>
</html>
<?php
}
Instead of use a return, change to echo. return means that you want return something to outside of the function. One way of use a return would be:
function displayMessage($msg)
{
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
<title>Error sending message</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div style="box-sizing: border-box; width:100%;font-family:arial;font-size:16px;color:#333333;background:#ffe6e3;padding:10px;background:#ffe6e3;border:1px solid #fb8d8d;">
'.$msg.'
</div>
</body>
</html>';
}
And when you call the function you just do:
<?php echo displayMessage(); ?>
Or you can change to echo:
function displayMessage($msg)
{
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"/>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"/>
<title>Error sending message</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div style="box-sizing: border-box; width:100%;font-family:arial;font-size:16px;color:#333333;background:#ffe6e3;padding:10px;background:#ffe6e3;border:1px solid #fb8d8d;">
'.$msg.'
</div>
</body>
</html>'
}
And call the function:
<?php displayMessage(); ?>
I am trying to load a projects.php file into a higher-level index.php file and want to maintain all the .js .css and any further nested (in .js files) .php files, that are declared in the projects.php file.
My index.php file goes like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BLST</title>
</head>
<body>
<?php $projectsPage = "/tables/php/projects.php"?>
<li>Projects</li>
<?php if(is_null($_GET["page"])) {
$page = "";
}else{
$page = $_GET["page"];
}
include($page);
?>
</body>
</html>
My projects.php file is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Projects</title>
<style type="text/css">
#import "css/test.css";
#import "http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/themes/smoothness/jquery-ui.css";
</style>
<script type="text/javascript" language="javascript" charset="utf-8" src="js/jquery.min.js"></script>
</head>
The issue is that none of the files in projects.php are found. This is because the browser is looking to my main directory now (where index.php is).
The test.css is in "tables/php/css/test.css" and what about the location of projects.php and index.php.
I think the answer to these will solve the problem.
I need to add url of video/audio to a player on my website.
For Example: I got this code from the "src" of an embed tag
http://www.ndtv.com/common/videos/flash/player/new-wrapper/NDTVVideoPlayer.swf?1384167757
And it did not work.
Please suggest how to get the proper URL,
The media Player is 'MP Plyaer'
Embed your SWF like this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Embed SWF</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("http://www.ndtv.com/common/videos/flash/player/new-wrapper/NDTVVideoPlayer.swf?1384167757", "myContent", "300", "120", "9.0.0");
</script>
</head>
<body>
<div id="myContent">
<p>NDTV SWF</p>
</div>
</body>
</html>
I am using a php script that has a file header.php with the normal web page header info. However, when I add the viewport tag it throws an error.
header.php:
<?php
/*
UserCake Version: 2.0.2
http://usercake.com
*/
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>".$websiteName."</title>
<link href='".$template."' rel='stylesheet' type='text/css' />
<script src='models/funcs.js' type='text/javascript'>
</script>
</head>";
?>
Error returned:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /homepages/30/d332080598/htdocs/azotusorg/usercake/models/header.php on line 10
Thanks for any help on this!
You are not escaping double quotes here
<?php
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>".$websiteName."</title>
<link href='".$template."' rel='stylesheet' type='text/css' />
<script src='models/funcs.js' type='text/javascript'>
</script>
</head>";
?>
OR use single quotes
<?php
echo "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0'/>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>".$websiteName."</title>
<link href='".$template."' rel='stylesheet' type='text/css' />
<script src='models/funcs.js' type='text/javascript'>
</script>
</head>";
?>