jquery & php - uosis.mif.vu.ltuosis.mif.vu.lt/~meglinskas/m/4.pdfjquery mobile, įvykiai (2)...
Post on 09-Mar-2019
218 Views
Preview:
TRANSCRIPT
jQuery & PHP
Web technologijos
• Hostingas
• JavaScript
• PHP
Kelios hostingo kompanijos
• serveriai.lt
• hostex.lt
• hostinger.lt• Nemokamas hostingas su PHP/mysql
• http://mindaugas.zz.mu/jm1.html
Hostingo paslaugų apžvalga
• Prisijungimas
• Teksto redagavimas
• MySQL duomenų bazė
JavaScript
• Programavimo kalba savo sintakse primenanti Java/C
• Interpretuojama naršyklėje
<script type="text/javascript">document.write("Hello World!");</script>
http://jsfiddle.net/
http://jsfiddle.net/dTpUx/http://jsfiddle.net/sidonaldson/pes2d/
Kintamieji
• Trys kintamųjų tipai:• String
• Number
• Boolean
Funkcijosfunction isPrime(n)
{
if (n < 2) {
return false;
}
else if (n == 2) {
return true;
}
else {
for (var i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
<script type="text/javascript">
if (isPrime(7)) {
document.write(testNum + " <b>is</b> a
prime number.");
}
else {
document.write(testNum + " <b>is not</b> a
prime number.");
}
</script>
Objektai
function Die(sides)
{
this.numSides = sides;
this.numRolls = 0;
this.roll = roll; // define a pointer to a function
}
function roll()
{
this.numRolls++;
return Math.floor(Math.random()*this.numSides) + 1;
}
Panaudojimas
die6 = new Die(6);
roll6 = die6.roll();
jQuery
<div id=“divID“ class=“divClass“>
...</div>
$(‘#divID‘).html(‘<b>text</b>‘);
$(‘.divClass‘).html(‘<i>tekstas</i>‘);
$("#p1").css("color","red").slideUp(2000).slideDown(2000);
Įvykiai - Document ready, www
$( document ).ready(function() {
console.log( "ready!" );
});
jQuery Mobile, pageinit
<script type="text/javascript">
$( document ).on( "pageinit", "#aboutPage", function(event) {
alert( "jQuery Mobile!" );
});
</script>
jQuery Mobile, įvykiai
hashchangeEnables bookmarkable #hash history.
NavigateA wrapper event for both hashchange and popstate
orientationchange eventDevice portrait/landscape orientation event
PagebeforechangeTriggered twice during the page change cyle: First prior to any page loading or transition and next after page loading completes successfully, but before the browser history has been modified by the navigation process.
PagebeforecreateTriggered on the page being initialized, before most plugin auto-initialization occurs.
PagebeforehideTriggered on the “fromPage” we are transitioning away from, before the actual transition animation is kicked off.
PagebeforeloadTriggered before any load request is made.
PagebeforeshowTriggered on the “toPage” we are transitioning to, before the actual transition animation is kicked off.
PagechangeThis event is triggered after the changePage() request has finished loading the page into the DOM and all page transition animations have completed.
PagechangefailedThis event is triggered when the changePage() request fails to load the page. Callbacks for this particular event will be passed a data object as the 2nd arg.
PagecreateTriggered when the page has been created in the DOM (via ajax or other) but before all widgets have had an opportunity to enhance the contained markup.
PagehideTriggered on the “fromPage” after the transition animation has completed.
PageinitTriggered on the page being initialized, after initialization occurs.
PageloadTriggered after the page is successfully loaded and inserted into the DOM.
PageloadfailedTriggered if the page load request failed.
jQuery Mobile, įvykiai (2)
PageremoveTriggered just before the framework attempts to remove an external page from the DOM.
PageshowTriggered on the “toPage” after the transition animation has completed.
ScrollstartTriggers when a scroll begins.
ScrollstopTriggers when a scroll finishes.
SwipeTriggered when a horizontal drag of 30px or more (and less than 75px vertically) occurs within 1 second duration.
SwipeleftTriggered when a swipe event occurs moving in the left direction.
SwiperightTriggered when a swipe event occurs moving in the right direction.
TapTriggered after a quick, complete touch event.
TapholdTriggered after a sustained complete touch event.
ThrottledresizeEnables bookmarkable #hash history.
UpdatelayoutTriggered by components within the framework that dynamically show/hide content.
Click
$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
JSON pakrovimas
<div id="change">Hello world</div>
<script>
$( document ).on( "pageinit", "#aboutPage", function( event ) {
$.getJSON( "json.php", function( data ) {
$('#change').html( data.description );
});
});
</script>
JSON masyvas
$.getJSON("json.php", function(data){
for (var i=0, len=data.length; i < len; i++) {
console.log(data[i].description);
}
});
PHP
• PHP – Personal Home Page
• Sintaksė primena – C ir Perl kalbą
• Failo išplėtimas .php
• PHP sakiniai įstatomi kaip <?php ... ?>
• PHP kodas yra interpretuojamas
<p><?php$myvar = "Hello World!"; echo $myvar;?></p>
PHP „Hello world“
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
PHP kintamieji
• Prasideda su $
• $kinamasis = "value";
• $kintamasis = 1;
• Tipas yra nustatomas pagal pirmą priskirimą
• $apjungtos_eilues = " pirma " . " antra " ;
Kintamųjų tipai
• Integer
• Double
• Boolean
• NULL
• String
• Array
• Object
• Resource
PHP valdymo struktūros
if, else, elseif
while, do-while
for, foreach
break, continue, switch
require, include, require_once, include_once
switch
switch ($i) {
case 0:
echo "i equals 0";
break;
case 1:
echo "i equals 1";
break;
case 2:
echo "i equals 2";
break;
}
Failų prijungimas
• require(), include(), include_once(), require_once() naudojami prijungti išorinius failus
Masyvai
• $mano_masyvas = array(1, 2, 3, 4, 5);
• $aukstai = "aukstas1 aukstas2 aukstas3 aukstas4";
• $namas = explode(" ", $aukstai);
• Kiekvienas masyvo elementas gali būti tiek kintamasis, tiek kitas masyvas, tiek objektas
• Masyvai nėra tipizuojami
foreach
$colors = array('red', 'blue', 'green', 'yellow');
foreach ($colors as $color) {
echo "Do you like $color?\n";
}
PHP klasės ir JSON
<?php
class SimpleClass
{
public $var = 'a default value';
public $description = 'product description';
public function displayVar() {
echo $this->var . ' ' . $this->description ;
}
}
$instance = new SimpleClass();
echo(json_encode($instance));
?>
GET ir POST parametrai
www.mysite.lt/index.php?link=next$link = $_GET['link'];
$post_param = $_POST['param'];
Pavyzdys
<form action="form.php" method="post">Name: <input type="text" name="yourname"><br />Phone: <input type="text" name="phone"><br />Email: <input type="text" name="email"><br /><input type="submit" value="Submit"></form>
<?phpecho('Name: ' . $_POST['yourname']);?>
MySql select
$con=mysqli_connect("mysql.hostinger.lt","u606800381_test","passpass","u606800381_test");
if (mysqli_connect_errno())
{ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }
$result = mysqli_query($con,"SELECT * FROM AllData");
while($row = mysqli_fetch_array($result))
{
echo $row['name'] . " " . $row['surename'];
echo "<br>";
}
mysqli_close($con);
<?php
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'world');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
$stmt->bind_param('sssd', $code, $language, $official, $percent);
$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
$stmt->close();
$mysqli->query("DELETE FROM CountryLanguage WHERE Language='Bavarian'");
printf("%d Row deleted.\n", $mysqli->affected_rows);
$mysqli->close();
?>
top related