Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Windows Azure > Windows Azure (Mobile Services) and HTML/JavaScript (jQuery) > ตอนที่ 2 : สร้าง Table และ Insert ข้อมูล Azure Mobile Services ด้วย HTML และ JavaScript



Clound SSD Virtual Server

ตอนที่ 2 : สร้าง Table และ Insert ข้อมูล Azure Mobile Services ด้วย HTML และ JavaScript

ตอนที่ 2 : สร้าง Table และ Insert ข้อมูล Azure Mobile Services ด้วย HTML และ JavaScript บทความนี้เราจะมาเขียน HTML และ JavaScript เพื่อติดต่อกับ Azure Mobile Services ในรูปแบบที่เราขียนเอง ด้วยการ Insert ข้อมูลจาก HTML Form รับค่าผ่าน JavaScript ด้วย jQuery และนำข้อมูลที่ได้ไป Insert ส่งไปที่ Mobile Services ของ Windows Azure ซึ่งรูปแบบการเขียนนั้นจะต้องบอกว่าง่ายมาก เพียงเขียน Code ของ JavaScript ประมาณ 4-5 บรรทัดก็สามารถที่จะ Insert ข้อมูลได้แล้ว

ในขั้นแรกเราจะต้องทำการสร้าง Table หรือตารางบน Azure Mobile Services ไว้รองรับข้อมูลที่จะถูกส่งมาจาก HTML และ JavaScript ซึ่งรูปแบบที่ใช้เขียนนั้นจะใช้ Syntax ของ jQuery เป็นหลัก

Azure Mobile Services HTML JavaScript

ไปยังหน้า Portal Management ของ Mobile Services

Azure Mobile Services HTML JavaScript

ในกรณีที่เราต้องการสร้าง HTML และ JavaScript เพื่อติดต่อกับ Azure Mobile Services ในแบบที่เราต้องการ สามารถปฎิบัติตามคำแนะนำ ในหน้า Get Started จะแสดงรายละเอียดของการเชื่อมต่อ และได้อธิบายไว้ในบทความก่อน ๆ หน้านี้แล้ว


ขั้นตอนการสร้าง Table หรือตาราง

Azure Mobile Services HTML JavaScript

คลิกที่ DATA และเลือก CREATE

Azure Mobile Services HTML JavaScript

ใส่ชื่อตารางในที่นี้จะใส่เป็น MyMember

Azure Mobile Services HTML JavaScript

ได้ตารางขึ้นมา 1 รายการชื่อว่า MyMember








Azure Mobile Services HTML JavaScript

ให้คลิกเข้าไปใน Table (ตาราง) ซึ่งตอนนี้ยังไม่มี Column และ Rows

Azure Mobile Services HTML JavaScript

เมนู SCRIPT เป็นพวก Script ที่ไว้ทำหน้าที่รับข้อมูลจาก Windows Phone แล้ว Insert ลงใน Table การทำงานคล้าย ๆ กับ Stored Procedure ซึ่งเราสามารถเขียน Script เพิ่มเติมได้ แต่ตอนนี้แนะนำให้กำหนดเป็นค่า Default ซะก่อน

Azure Mobile Services HTML JavaScript

หลัก ๆ จะมีอยู่ 4 ตัวคือ Insert , Update , Delete , Read

ขั้นตอนการเขียน HTML และ JavaScript เพื่อเชื่อมต่อกับ Azure Mobile Services

var client = new WindowsAzure.MobileServiceClient('https://thaicreate.azure-mobile.net/', 'uJPAhkAkcTBuTyCNxaOSnDKFzkoYqB49'),
สร้าง URL และ API Keys สำหรับเชื่อมต่อ

myMemberTable = client.getTable('MyMember');
เรีกยใช้งานตารางที่ได้สร้างไว้

myMemberTable.insert({ name: sname, email: semail }).then(refreshMyMember, handleError);
การ Insert ข้อมูล เชนในตัวอย่างมี Column ชื่อว่า name และ email (ในกรณีที่ไม่มี Column จะมีการสร้างขึ้นใหม่อัตโนมัติ)

Code ทั้งหมด

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8' />
        <title>ThaiCreate.Com</title>
        <link rel='stylesheet' href='styles.css' />
        <meta name='viewport' content='width=device-width' />
        <!--[if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js"></script><![endif]-->
        <script src='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js'></script>
        <script src='https://thaicreate.azure-mobile.net/client/MobileServices.Web-1.0.0.min.js'></script>
    </head>
    <body>

	<script type="text/javascript">
		$(document).ready(function(){

				var client = new WindowsAzure.MobileServiceClient('https://thaicreate.azure-mobile.net/', 'uJPAhkAkcTBuTyCNxaOSnDKFzkoYqB49'),

				myMemberTable = client.getTable('MyMember');

				function refreshMyMember() {
						$('#summary').html('Add form');
				}

				function handleError(error) {
					var text = error + (error.request ? ' - ' + error.request.status : '');
					$('#errorlog').append($('<li>').text(text));
				}

				// Handle insert
				$('#add-item').submit(function(evt) {
					var tname = $('#txtName');
					var temail = $('#txtEmail');
						sname = tname.val();
						semail = temail.val();
					if (sname !== '') {
						myMemberTable.insert({ name: sname, email: semail }).then(refreshMyMember, handleError);
					}
					tname.val('').focus();
					temail.val('').focus();
					evt.preventDefault();
				});

				// On initial load, start by fetching the current data
				refreshMyMember();

		});
	</script>

        <div id='wrapper'>
            <article>
                <header>
                    <h2>Windows Azure</h2>
                    <h1>Mobile Services</h1>

                    <form id='add-item'>
                        <button type='submit'>Add</button>
                        <div>
						Name : <input type='text' id='txtName' placeholder='Enter your name' style='width:200px' />
						Email : <input type='text' id='txtEmail' placeholder='Enter your email' style='width:300px' /></div>
                    </form>
                </header>

                <ul id='todo-items'></ul>
                <p id='summary'>Loading...</p>
            </article>

            <footer>
                <a href='http://www.windowsazure.com/en-us/develop/mobile/'>
                    Learn more about Windows Azure Mobile Services
                </a>
                <ul id='errorlog'></ul>
            </footer>
        </div>

    </body>
</html>


Screenshot

Azure Mobile Services HTML JavaScript

Form สำหรับ Input ข้อมูล

Azure Mobile Services HTML JavaScript

ทดสอบ Input ข้อมูล

Azure Mobile Services HTML JavaScript

เมื่อกลับไปดูที่ Mobile Services บน Windows Azure ข้อมูลก็จะถูก Insert เข้าไปในตาราง Table








บทความถัดไปที่แนะนำให้อ่าน


บทความที่เกี่ยวข้อง


   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-08-26 06:10:14 / 2017-03-24 12:01:37
  Download : Download  ตอนที่ 2 : สร้าง Table และ Insert ข้อมูล Azure Mobile Services ด้วย HTML และ JavaScript
 Sponsored Links / Related

 
ตอนที่ 1 : การสร้าง Azure Mobile Services ทำงานร่วมกับ HTML และ JavaScript
Rating :

 
ตอนที่ 3 : อ่าน Data จาก Table ของ Azure Mobile Services และแสดงผลบน HTML และ JavaScript
Rating :

 
ตอนที่ 4 : อ่านข้อมูล Azure Mobile Services แบบมีเงื่อนไข Where และแสดงผล HTML และ JavaScript
Rating :

 
ตอนที่ 5 : การทำ Authentication in Azure Mobile Services ด้วย HTML และ JavaScript
Rating :

 
ตอนที่ 6 : การทำ Validate และ Modify data in Mobile Services บน HTML และ JavaScript
Rating :

 
ตอนที่ 7 : การทำ Refine Mobile Services queries with paging บน HTML และ JavaScript
Rating :

 
ตอนที่ 8 : การเขียน Scripts to authorize users in Mobile Services บน HTML และ JavaScript
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่