بایگانی برای ‘ajax’ دسته

دوجو ۱٫۴

شنبه, ۲۸ آذر ۱۳۸۸

میتونم بگم دوجو مفیدترین چیزی که من تو طراحی وب یاد گرفتم.این اصلا مهم نیست ، مهم اینه بعد از چند ماه انتظار ورژن ۱٫۴ این ابزار منتشر شد.

ojo 1.4 is hot off the presses, with more than seven months of significant improvements to performance, stability, and features.
Of particular interest:
IO Pipeline topics
dojo.cache
dojo.contentHandlers
dojo.hash with native HTML5 onhashchange event support where available
Traversal and manipulation for NodeLists (the return value for dojo.query)
dojo.ready (easier to type than dojo.addOnLoad)
Hundreds of refinements to the Dijit API and collection of Dijits, and a few new widgets in DojoX
DataChart widget and other improvements to charting
dojox.drawing lands!
Editor improvements and new plug-ins in both Dijit and DojoX
Grid is faster, and the EnhancedGrid lands!
ForestStoreModel for the TreeGrid
GFX improvements
dojox.jq, a very experimental module aimed at trying to match the jQuery API as close as possible, but using Dojo underneath
Dojo build system optionally supports the Google Closure Tools compiler
Significant speed improvements, especially in IE
Read the full Dojo 1.4 release notes for more details! And thanks to everyone in the Dojo community that helped make this release great!

Dojo 1.4 is hot off the presses, with more than seven months of significant improvements to performance, stability, and features.

Of particular interest:

IO Pipeline topics

dojo.cache

dojo.contentHandlers

dojo.hash with native HTML5 onhashchange event support where available

Traversal and manipulation for NodeLists (the return value for dojo.query)

dojo.ready (easier to type than dojo.addOnLoad)

Hundreds of refinements to the Dijit API and collection of Dijits, and a few new widgets in DojoX

DataChart widget and other improvements to charting

dojox.drawing lands!

Editor improvements and new plug-ins in both Dijit and DojoX

Grid is faster, and the EnhancedGrid lands!

ForestStoreModel for the TreeGrid

GFX improvements

dojox.jq, a very experimental module aimed at trying to match the jQuery API as close as possible, but using Dojo underneath

Dojo build system optionally supports the Google Closure Tools compiler

Significant speed improvements, especially in IE

Read the full Dojo 1.4 release notes for more details! And thanks to everyone in the Dojo community that helped make this release great!

حذف عکس های لود نشده با دوجو

دوشنبه, ۲۳ شهریور ۱۳۸۸

چند روز پیش دیوید والش تو مطلبی با عنوان Remove Broken Images Using MooTools or jQuery نحوه حذف عکس های لود نشده با جی کوئری و موتولز نوشته که منم راغب شدم با دوجو اون تکه کد بازنویسی کنم.

البته طبق معمول IE از این event پشتیبانی نمیکنه.

try it:

dojo.addOnLoad(function(){
   dojo.query("img").connect("onerror", function(evt){
       dojo.destroy(evt.target);
   });
});

اتصال با dojo.hitch

پنجشنبه, ۱۹ شهریور ۱۳۸۸

api.dojotoolkitdocs.dojocampus

به زبان ساده
dojo.hitch(foo, "bar")();
//runs foo.bar() in the scope of foo
dojo.hitch(foo, myFunction);
//returns a function that runs myFunction in the scope of foo

بعضی اوقات احتیاج داریم یک متد از یک شیء به عنوان آرگومان به تابع دیگر بدیم.خیلی از برنامه نویسا خسته می شن از بس برای حل این مشکل مینویسن

somFunction(somObject.someMethod)

و نتیجه هم نمی گیرن ، dojo.hitch این مشکل حل کرده

بزارین یک تلاش ساده برای همین مشکلی که گفتم انجام بدیم و متد m از شی o را به عنوان آرگومان به تابع دیگری ارسال کنیم،o.m صداش می کنیم.یه مثال ساده از یک اکومولاتور که جمع می کنه و نتیجه بازگشت میده.تو این کد theAccumulator.getResult همون o.m هست
var theAccumulator= {
	total: 0,
	clear: function() {
		this.total= 0;
	},
	add: function(x) {
		this.total+= x;
	},
	getResult: function() {
		return this.total;
	}
};
بعد به تابعی احتیاج داریم که تابعی دیگر را (یعنی theAccumulator.getResult) به عنوان ورودی گرفته و نتیجه بازگشتی رو نمایش بده:
الان ما ۱۰۰ و ۲۰۰ اضافه میکنیم و نتیجه را با عبور دادن theAccumulator.getResult در تابع printResult چاپ میکنیم.شاید خیلی از برنامه نویسا اینجور عمل کنند.
theAccumulator.clear();
theAccumulator.add(100);
theAccumulator.add(200);
printResult(theAccumulator.getResult);
ما انتظار داریم پیغام “result= 300” نمایش داده شود ولی “result= undefined” دیده می شود.مشکل همینجاست:وقتی theAccumulator.getResult به تابع printResult ارسال می شود ، تابع هیچ مقداری ندارد.وقتی پارامتر f بوسیله تابع printResult احضار می شود.this ارجاع داده میشه به یک شیء گلوبال و متغیر گلوبال total [ارزیابی | سنجیده ] میشه ، نه متغیر total در شیء theAccumulator که منظور ما بوده است.این مشکل میتونه به این صورت حل بشه:
printResult(function(){return theAccumulator.getResult();});
وقتی تابع function(){return theAccumulator.getResult();} توسط printResult فراخوانی میشه ، ما صراحتا getResult از شیء theAccumulator فراخوانی می کنیم.
تابع dojo.hitch میتونه یک یا دو یا … ورودی بگیره .اگر ۲ ورودی بگیره آرگومان اول به عنوان یک شیء و آرگومان دوم به عنوان یک رشته یا تابع است.
printResult(dojo.hitch(theAccumulator, "getResult" ));

dojo.formToQuery

سه شنبه, ۲۷ مرداد ۱۳۸۸

یکی از راههای ارسال مقادیر فرم ، استفاده از متد GET . و اگه برای ارسال مقادیر با متد GET در صفحاتی که به صورت ای جکس نوشته شده باشه مصر باشیم باید تمام node های یک فرم را اسکن کرده و با تابع encodeURI انکد کنیم.

تابع formToQuery دوجو دقیقا همین کارو انجام میده یعنی ID یک فرمو میگیره و مقداریو بر میگردونه که دقیقا GET میشه.نقطه قوتش اینه که از ورودی های hidden و آرایه ها و … کاملا پشتیبانی میکنه.

try it:

تشخیص درخواست های ajax در php

جمعه, ۹ مرداد ۱۳۸۸

همیشه نوشتن صفحاتی که هم از URL و هم از طریق فانکشن کار کنه لذت بخشه.چون با چند خط اضافه کد نوشتن میتونیم از آپلود و ویرایش کردن صفحات مختلف جلوگیری کنیم.البته در بعضی از اوقات  صفحات فقط باید از طریق درخواست های ajax پاسخگو باشند،در این مواقع میتونیم برای دفع کنجکاوی های (حملات) نه چندان مهم از هدرها استفاده کرد.

[HTTP_X_REQUESTED_WITH] => XMLHttpRequest

if( isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
/* special ajax here */
}