สอบถามปัญหาจากการที่ใช้ php เขียนเป็น mobile app โดยมี jquery mobile

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามปัญหาจากการที่ใช้ php เขียนเป็น mobile app โดยมี jquery mobile

สอบถามปัญหาจากการที่ใช้ php เขียนเป็น mobile app โดยมี jquery mobile
ผมติดปัญหาที่แผนที่ไม่ขึ้นมาแสดงครับ

จากไฟล์ list.php ที่มี jquery mobile

ไปเรียก location.php

แต่ถ้าเป็นไฟล test.php เพียวๆ โดยไม่ jquery กลับขึ้นมาครับ

พอจะมีแนวทางแก้ไขอย่างไรบ้างครับ ขอบคุณครับ ^^


Natjadee 202.12.74.xxx 11-07-2014 16:58:21

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
นี่เป็นตัวโค้ดน่ะคับ

list.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="../jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css">
<script src="../jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="../jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
</head>

<body>
<div data-role="page" id="page">
  <div data-role="header" data-theme="d">
    <h1>Header</h1>
  </div>
  <div data-role="content">
  
    <ul data-role="listview" data-inset="true" data-theme="d" data-divider-theme="e">
			<li data-role="list-divider">Name</li>
				<?
				$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
				$objDB = mysql_select_db("test");
				$strSQL = " SELECT ID,name FROM test";

				$objQuery = mysql_query($strSQL) or die (mysql_error());
				while($objResult = mysql_fetch_array($objQuery))
				{
				?>
					<li><a href="location.php?ID=<?=$objResult["ID"];?>"><?=$objResult["name"];?></a></li>
				<?
				}
				?>
		</ul>
  
  
  
  
  </div>
  <div data-position="fixed" data-role="footer" data-theme="d">
    <h4>Footer</h4>
  </div>
</div>
</body>
</html>

location.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="../jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css">
<script src="../jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="../jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head>

<body>
<div data-role="page" id="page">
  <div data-role="header" data-theme="d">
    <h1>Header</h1>
  </div>
  <div data-role="content">
  		<?php
						
						$con=mysqli_connect("localhost","root","","test");
						 //Check connection
						if (mysqli_connect_errno()) {
						  echo "Failed to connect to MySQL: " . mysqli_connect_error();
						}
						
						$result = mysqli_query($con,"SELECT * FROM position where ID = '".$_GET["ID"]."' ");
	
						$row = mysqli_fetch_array($result);
						$lat = $row['latitude'];
						$log = $row['longitude'];
	
						
						mysqli_close($con);
           			?> 
             <script>
					function success(position) {
						var lat = <?=$lat?>;
						var lng = <?=$log?>;
					  var mapcanvas = document.createElement('div');
					  mapcanvas.id = 'mapcontainer';
					  mapcanvas.style.height = '500px';
					  mapcanvas.style.width = '100%';
					  mapcanvas.style.padding = '0px';
						
					  document.querySelector('article').appendChild(mapcanvas);
					
					  var coords = new google.maps.LatLng(lat,lng);
					  
					  var options = {
						zoom: 15,
						center: coords,
						mapTypeControl: false,
						navigationControlOptions: {
							style: google.maps.NavigationControlStyle.SMALL
						},
						mapTypeId: google.maps.MapTypeId.ROADMAP
					  };
					  var map = new google.maps.Map(document.getElementById("mapcontainer"), options);
					
					  var marker = new google.maps.Marker({
						  position: coords,
						  map: map,
						  title:"You are here!"
					  });
					}
					
					if (navigator.geolocation) {
					  navigator.geolocation.getCurrentPosition(success);
					} else {
					  error('Geo Location is not supported');
					} 
			</script>
           
        <div align="center">
                
                <article id="wrapper">
                </article>
                
            </div>

  </div>
  <div data-position="fixed" data-role="footer" data-theme="d">
    <h4>Footer</h4>
  </div>
</div>

</body>
</html>


test.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
    <ul data-role="listview" data-inset="true" data-theme="d" data-divider-theme="e">
			<li data-role="list-divider">Name</li>
				<?
				$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
				$objDB = mysql_select_db("test");
				$strSQL = " SELECT ID,name FROM test";

				$objQuery = mysql_query($strSQL) or die (mysql_error());
				while($objResult = mysql_fetch_array($objQuery))
				{
				?>
					<li><a href="location.php?ID=<?=$objResult["ID"];?>"><?=$objResult["name"];?></a></li>
				<?
				}
				?>
		</ul>
  
 
</body>
</html>


Natjadee 202.12.74.xxx 11-07-2014 17:00
 ความคิดเห็นที่ 2

มีสองแบบ ง่ายสุด คือใส่ data-ajax="false" เข้าไปในลิ้งค์ที่ส่งไป

อีกแบบจะเป็นทำเป็นฟังก์ชั่น เพราะ jquerymobile เรียกแต่ละหน้าเป็น ajax

ถ้าแนะนำ ก็น่าจะเป็นวิธีแรก

ตรงลิ้งค์ ให้ใ่ส่ data-ajax="false"  เข้าไป เช่น

 

<li><a data-ajax="false" href="location.php?ID=<?=$objResult["ID"];?>"><?=$objResult["name"];?></a></li>


ninenik 1.47.211.xxx 11-07-2014
 ความคิดเห็นที่ 3
ได้แล้ว ขอบคุณมากๆๆเลยครับ 


Natjadee 202.12.74.xxx 11-07-2014 23:13
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ