_jquery دا ajax ئارقىلىق مەزمۇننى يۈكلەش دەرسلىكى
1-قەدەمدە بىز پاكىز بولغان ۋە ئاددى بولغان ئاساسلىق بۆلەكنى قۇرىمىز،بىزبۇبۆلەكنى container دەپ چاقىردۇق.
top:يەنى بۆلەك تىزىملىكىنى ئۆز ئىچىگە ئالىدۇ
loading:يەنى يۈكلىنىش تەكچىسىنى ئۆز ئىچىگە ئالىدۇ
content:يەنى نۆۋەتتىكى رايۇننىڭ مەزمۇنىنى ئۆچىگە ئالىدۇ
ئەمدى بىز كودنى باشلايلى
2-قەدەمدە css نى لايھىلەيمىز.
css نىڭ ئاساسلىق كودى مانا بۇيەردە،بىزنى بۇنى main.css دەپ چاقىردۇق!
كىلىڭلار بالىلار ئەمدى بىز jquery قىسمىغا پىدائىيلارچە ئاتلىنايلى.
3-قەدەمدە بىز jquery ئارقىلق مەزمۇننى سېھرىلك ھالدا يۈكلەيمىز.
بىز يەنە سۆزلەيمىزكى بىزئىككى خىل ئۇسۇلدا مەزمۇننى يۈكلەيمىز:يەنى ئوخشاش ھۆججەتىكى ھەربىر رايۇننى جايلاشتۇرىمىز(section.html) ھەمدە بارلىق مەزمۇننى external.html دىن يۈكلەيمىز.
بىز ئاشۇ مەزمۇنى بىلەن ئىككى دانە سىرتقى ھۆججەت ھاسىل قىلىمىز(external) .
section.html بۇيەردە
بىز ئۆزىمىزنىڭ menu.js ھۆججىتىگە قاراپ باقايلى ،ئەسلەڭكى بارلىق كودلار jquery ھادىسسىنىڭ ready سىدا بولىدۇ،جۈملىدىن فۇنكىسيە،چۈنكى بىز jquery قوللانمىسنى ئۆزگەرگۈچى مىقداردا ئىشلىتىمىز،شۇنداقلا يەنە قايتىلايمەن،يازدىغان كودلار ready event دە بولىدۇ.
بىز يۈكلەش تەكچىسىنى باشقۇرۇش ئۈچۈن ئىككى فۇنكىسيە ھاسىل قىلدۇق:يەنى hideloading() ۋە showloading(),بۇلار چىشتىلىق بولغان رايۇننى كۆرستىدۇ ۋە يۇشۇرىدۇ.
كودى بۇيەردە
بىز fadeOut نىڭ ئورنىغا fadeTo نى ئىشلەتتۇق چۈنكى fadeOut ھەرىكەت ئاخىرلاشقاندا display:none; نى قوللىنىدۇ،شۇڭلاشقا بىز تىزىملىك ھەربىر ئىلىمىنتدىكى Click event نى باشقۇرۇشىمىز كىرەك.
شۇنداق قىلىپ بىزنىڭ jquery دا ajax ئارقىلىق مەزمۇن يۈكلەش دەرسىمىز ئاخرىلاشتى!
ئاللاھ خالىسا بۇ دەرسلىكنىڭ pdf نۇسخسى پات ئارىدا سىلەر بىلەن يۈز كۆرىشىدۇ!.
1-قەدەمدە بىز پاكىز بولغان ۋە ئاددى بولغان ئاساسلىق بۆلەكنى قۇرىمىز،بىزبۇبۆلەكنى container دەپ چاقىردۇق.
top:يەنى بۆلەك تىزىملىكىنى ئۆز ئىچىگە ئالىدۇ
loading:يەنى يۈكلىنىش تەكچىسىنى ئۆز ئىچىگە ئالىدۇ
content:يەنى نۆۋەتتىكى رايۇننىڭ مەزمۇنىنى ئۆچىگە ئالىدۇ
ئەمدى بىز كودنى باشلايلى
- <!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" xml:lang="en">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <meta name="keywords" content="yensdesign, tutorial, ajax, jquery, javascript, load content" />
- <meta name="description" content="How to load content via AJAX in jQuery - yensdesign.com"/>
- <title>How to load content via AJAX in jQuery. By yensdesign.com</title>
- <link rel="stylesheet" type="text/css" media="screen" href="css/main.css" />
- </head>
- <body>
- <div id="container">
- <div id="top">
- <h1><a href="/">yensdesign - Tutorials, Web Design and Coding</a></h1>
- <ul id="menu">
- <li id="home">Home</li>
- <li id="news">News</li>
- <li id="interviews">Interviews</li>
- <li id="external">External</li>
- </ul>
- <span class="clear"></span>
- </div>
- <div id="loading">
- <img src="css/images/loading.gif" alt="Loading..." />
- </div>
- <div id="content">
- <h2>Home</h2>
- <p>
- Lorem Ipsum is simply <a
href="">dummy</a> text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
- </p>
- <p>
- Lorem Ipsum is simply dummy text of the
printing and <a href="">typesetting industry</a>. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also
the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
- </p>
- </div>
- <div id="footer">
- <p>Made by <a
href="http://www.yensdesign.com">yensdesign.com</a>. We hope
you find this tutorial useful for your personal projects :)</p>
- </div>
- </div>
- <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"></script>
- <script type="text/javascript" src="menu.js"></script>
- </body>
- </html>
- </body>
2-قەدەمدە css نى لايھىلەيمىز.
css نىڭ ئاساسلىق كودى مانا بۇيەردە،بىزنى بۇنى main.css دەپ چاقىردۇق!
- @CHARSET "UTF-8";
- /******* GENERAL RESET *******/
- html, body, div, span, applet, object, iframe, h1, h2, h3,
h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite,
code, del, dfn, em,
- font, img, ins, kbd, q, s, samp, small, strike, strong,
sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label,
legend, table, caption, tbody,
- tfoot, thead, tr, th, td {
- border: 0pt none;
- font-family: inherit;
- font-size: 100%;
- font-style: inherit;
- font-weight: inherit;
- margin: 0pt;
- padding: 0pt;
- vertical-align: baseline;
- }
- body{
- line-height: 14px;
- font-size: 12px;
- background: #fff;
- font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
- margin: 0pt;
- cursor: default;
- }
- table{
- border-collapse: separate;
- border-spacing: 0pt;
- }
- caption, th, td{
- font-weight: normal;
- text-align: left;
- }
- blockquote:before, blockquote:after, q:before, q:after{
- content: "";
- }
- blockquote, q{
- quotes: "" "";
- }
- input, textarea, select{
- font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
- font-size: 11px;
- }
- strong{
- font-weight: 700;
- }
- ul{
- list-style: outside;
- }
- a{
- cursor: pointer;
- color: #296ba5;
- text-decoration: none;
- }
- .clear{
- clear: both;
- height: 0;
- visibility: hidden;
- display: block;
- }
- /******* /GENERAL RESET *******/
- /******* REUSE *******/
- h1, h2, h3, h4, h5, h6{
- font-weight: 700;
- color: #6ea6fb;
- line-height: 1.8em;
- }
- h2{
- font-size: 22px;
- }
- /******* /REUSE *******/
- /******* CONTAINER *******/
- #container{
- width: 960px;
- margin: 0pt auto;
- color: #fff;
- }
- /******* /CONTAINER *******/
- /******* TOP *******/
- #top{
- margin: 0 auto;
- padding: 20px 0 0 0;
- }
- #top h1 a{
- background: transparent url(images/logo.jpg) no-repeat scroll left top;
- display: block;
- float: left;
- height: 46px;
- text-indent: -999999px;
- width: 205px;
- }
- /******* /TOP *******/
- /******* MENU *******/
- #top #menu{
- float: left;
- list-style-type: none;
- margin: 12px 0 0 26px;
- }
- #top #menu li{
- float: left;
- margin-right: 16px;
- text-transform: uppercase;
- color: #c2c2c2;
- }
- #top #menu li:hover{
- color: #6fa5fd;
- cursor: pointer;
- }
- /******* /MENU *******/
- /******* LOADING *******/
- #loading{
- text-align: center;
- visibility: hidden;
- }
- /******* /LOADING *******/
- /******* CONTENT *******/
- #content{
- color: #7e7e7e;
- margin: 0 0 20px 0;
- line-height: 1.3em;
- font-size: 11px;
- }
- #content p{
- margin-bottom: 0.7em;
- }
- #content a{
- font-weight: 700;
- color: #6fa5fd;
- border-bottom: 1px dotted #6fa5fd;
- }
- /******* /CONTENT *******/
- /******* FOOTER *******/
- #footer{
- background: #efefef;
- border: 1px solid #d0ccc9;
- padding: 10px;
- color: #7e7e7e;
- font-size: 11px;
- text-align: right;
- }
- /******* /FOOTER *******/
كىلىڭلار بالىلار ئەمدى بىز jquery قىسمىغا پىدائىيلارچە ئاتلىنايلى.
3-قەدەمدە بىز jquery ئارقىلق مەزمۇننى سېھرىلك ھالدا يۈكلەيمىز.
بىز يەنە سۆزلەيمىزكى بىزئىككى خىل ئۇسۇلدا مەزمۇننى يۈكلەيمىز:يەنى ئوخشاش ھۆججەتىكى ھەربىر رايۇننى جايلاشتۇرىمىز(section.html) ھەمدە بارلىق مەزمۇننى external.html دىن يۈكلەيمىز.
بىز ئاشۇ مەزمۇنى بىلەن ئىككى دانە سىرتقى ھۆججەت ھاسىل قىلىمىز(external) .
section.html بۇيەردە
- <div id="section_home">
- <h2>Home</h2>
- <p>
- Lorem Ipsum is simply <a
href="">dummy</a> text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
- </p>
- <p>
- Lorem Ipsum is simply dummy text of the printing
and <a href="">typesetting industry</a>. Lorem Ipsum has
been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the
leap into electronic typesetting, remaining essentially unchanged. It
was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
- </p>
- </div>
-
- <div id="section_news">
- <h2>News</h2>
- <p>
- We have released our forums, <a href="http://forums.yensdesign.com">check it out</a>!
- </p>
- </div>
-
- <div id="section_interviews">
- <h2>Interviews section</h2>
- <p>
- We have interviewed Victor Espigares, creator of <a href="http://www.visualizeus.com">visualizeus</a>!
- </p>
- </div>
- <div id="section_external">
- <h2>External content!</h2>
- In this case we are loading the External section from other external file, instead of use jQuery selectors in the sections.html file.</div>
بىز ئۆزىمىزنىڭ menu.js ھۆججىتىگە قاراپ باقايلى ،ئەسلەڭكى بارلىق كودلار jquery ھادىسسىنىڭ ready سىدا بولىدۇ،جۈملىدىن فۇنكىسيە،چۈنكى بىز jquery قوللانمىسنى ئۆزگەرگۈچى مىقداردا ئىشلىتىمىز،شۇنداقلا يەنە قايتىلايمەن،يازدىغان كودلار ready event دە بولىدۇ.
- $(document).ready(function(){
- // all the code goes here! including functions!!!
- });
بىز يۈكلەش تەكچىسىنى باشقۇرۇش ئۈچۈن ئىككى فۇنكىسيە ھاسىل قىلدۇق:يەنى hideloading() ۋە showloading(),بۇلار چىشتىلىق بولغان رايۇننى كۆرستىدۇ ۋە يۇشۇرىدۇ.
كودى بۇيەردە
- //يۈكلەش تەكچىسنى كۆرسىتىش
- function showLoading(){
- loading
- .css({visibility:"visible"})
- .css({opacity:"1"})
- .css({display:"block"})
- ;
- }
- //يۈكلەش تەكچىسىنى يوشۇرۇش
- function hideLoading(){
- loading.fadeTo(1000, 0);
- content.slideDown();
- };
بىز fadeOut نىڭ ئورنىغا fadeTo نى ئىشلەتتۇق چۈنكى fadeOut ھەرىكەت ئاخىرلاشقاندا display:none; نى قوللىنىدۇ،شۇڭلاشقا بىز تىزىملىك ھەربىر ئىلىمىنتدىكى Click event نى باشقۇرۇشىمىز كىرەك.
- //نى باشقۇرۇش click events
- sections.click(function(){
- //show the loading bar
- showLoading();
- //load selected section
- switch(this.id){
- case "home":
- content.slideUp();
- content.load("sections.html #section_home", hideLoading);
- break;
- case "news":
- content.slideUp();
- content.load("sections.html #section_news", hideLoading);
- break;
- case "interviews":
- content.slideUp();
- content.load("sections.html #section_interviews", hideLoading);
- break;
- case "external":
- content.slideUp();
- content.load("external.html", hideLoading);
- break;
- default:
- //ئەگەر بۇيەردە تاللانغان رايۇن بولمىسا يۈكلەش تەكچىسىنى يورۇشۇ
- hideLoading();
- break;
- }
- });
شۇنداق قىلىپ بىزنىڭ jquery دا ajax ئارقىلىق مەزمۇن يۈكلەش دەرسىمىز ئاخرىلاشتى!
ئاللاھ خالىسا بۇ دەرسلىكنىڭ pdf نۇسخسى پات ئارىدا سىلەر بىلەن يۈز كۆرىشىدۇ!.