![]() |
|
|||||||
| ثبت نام | کتابخانه فایل ها | راهنما | لیست کاربران | کلوب های کاربران | همه قسمت ها ، به عنوان خوانده شده علامت گذاری شوند |
| PHP در این بخش میتوانید درباره مطالب مربوط به PHP بحث و گفتگو کنید. |
![]() |
|
|
ابزار های تاپیک | طریقه نمایش |
|
|
#1 |
|
کاربر دائمی
![]() |
کاربا Ajax در حالت POST Request
من احتیاج به یه مثال قابل فهم و یا توضیح راجب آژاکس Ajax در حالت POST دارم.
قسمت GET رو بلد هستم واینکه نمیخوام غیر از جاوا و PHP چیزی داشته باشه ( مثل XML یا کدهای runtime ) (چجوری میشه با جاوا یه POST Request فرستاد؟ ) ممنون
__________________
You'll stay in my mind and in my way forever [لطفا http://barnamenevis.org/forum/images...ost_thanks.gif نکنید. ] |
|
|
|
|
|
#2 |
|
کاربر دائمی
![]() |
جوابشو یافتم
ممنون ;)
__________________
You'll stay in my mind and in my way forever [لطفا http://barnamenevis.org/forum/images...ost_thanks.gif نکنید. ] |
|
|
|
|
|
#3 |
|
.
![]() |
مسلما ممنون میشیم پاسخ رو ایجا بنویسید تا برای آیندگان مفید باشه :)
__________________
ایمیل من سایت من عضویت در جامعهی اهدای عضوDirect PGP key: http://tinyurl.com/66q5cy PGP key server: keyserver.ubuntu.com PGP name to search: omidmottaghi |
|
|
|
|
|
#4 |
|
کاربر دائمی
![]() |
حتما جناب مدیر.
فرض میکنم آجاکس رو بشناسید در حد get برای POST باید کاری کرد که بشه اطلاعات رو پست کرد البته من xml نمیخواستم ولی این روش از xmlhttprequest استفاده میکنه. با کدزیر یک xmlhttprequest درست میکنیم: کد:
<script language="javascript" type="text/javascript">
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
کد:
http.open("POST",url,true);
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
http.onreadystatechange = handleResponse;
http.send(data);
اینجا از تابع handleResponse استفاده کردیم برای چک کردن مراحل ارسال و دریافت پاسخ. که این تابع به این شکل هست: کد:
function handleResponse() {
if (http.readyState == 4) {
result = http.responseText;
alert('result is: '+result);
}
}
کد:
http.open("GET", str, true);
http.onreadystatechange = handleResponse;
http.send(null);
__________________
You'll stay in my mind and in my way forever [لطفا http://barnamenevis.org/forum/images...ost_thanks.gif نکنید. ] |
|
|
|
|
|
#5 |
|
کاربر جدید
![]() |
بله اما من این کارو می کنم حروفی را که در فرم تایپ می کنم به صورت سرهم در دیتابیس ذخیره می کنه مثلا:
وقتی می نویسم: Ahmad Rezai در دیتابیس اینجوری ذخیره می شه: AhmadRezai به نظر شما باید چه کار کرد؟ |
|
|
|
|
|
#6 |
|
کاربر تازه وارد
![]() تاریخ عضویت: اردیبهشت 1386
پست: 78
تشکرها: 11
16 بار تشکر شده در 13 پست
|
قسمتی از کتاب Ajax for Dummies
Passing Data to the Server with POST When you pass data to a URL by using the POST method, it’s encoded internally (in the HTTP request sent to the server), which makes sending data more secure than with GET (although not as secure as using a secure HTTPS connection to the server). In the following sections, you see how using the POST method works. Passing data by using the POST method in Ajax is a little different than using GET. As far as the PHP goes, you can recover data sent to a PHP script by using POST with the $_POST array, not $_GET. Here’s what that looks like in a new PHP script, options3.php: کد PHP:
applications when you use the POST method, in which case you have to use $HTTP_RAW_POST_DATA instead. This technique gives you the raw data string sent to the PHP script (such as “a=5&b=6&c=Now+is+the+time”), and it’s up to you to extract your data from it. How do you use the POST method in your JavaScript? It isn’t as easy as just changing “GET” to “POST” when you open the connection to the server: XMLHttpRequestObject.open(“POST”, url); //Won’t work by itself! It isn’t as easy as that, because you don’t URL-encode your data when you use POST. Instead, you have to explicitly send that data by using the XMLHttpRequest object’s send method. Here’s what you do. You set up the URL to open without any URL encoding this way in the getOptions function, which is the function that communicates with the server: کد PHP:
by using the open method and by specifying that you want to use the POST method: کد PHP:
that indicates the data in the request will be set up in the standard POST way. Here’s what that looks like: کد PHP:
object’s onreadystatechange property as before to handle asynchronous requests, as shown here: کد PHP:
And now comes the crux. Instead of sending a null value as you would if you were using the GET method, you now send the data you want the script to get. In this case, that’s scheme = 1, like this: کد PHP:
html, will use the POST method to send its data to options3.php, which will return its data in XML format. Very neat. If you want to use XML to send your data to the server-side program, the POST method works, too. That’s because you don’t have to explicitly encode the data you send to the server yourself, appending it to the end of an URL. (Some servers have limits on how long URLs can be.) To send your data as XML, you set a Request header so that the content type of your request will be “text/xml” instead of “application/x-wwwform- urlencoded”: کد PHP:
method, which goes something like this: کد PHP:
|
|
|
|
|
|
#7 |
|
کاربر جدید
![]() |
بابا یکی جواب ما رو بده؟
چه کارکنم من دارم از طریق روش پست آژاکس اطلاعات فرمم رو داخل بانک می ریزم اما تمامی حروف به هم چسبیده می شه و بعد داخل بانک ریخته می شه!!!!!!!!!!! مثلا: Razi Emami اینجوری ثبت می شه: RaziEmami؟ فکر می کنید مشکل چیه؟
__________________
بیرون ز تو نیست آنچه در عالم هست از خود بطلب هرآنچه خواهی که تویی |
|
|
|
|
|
#8 |
|
کاربر دائمی
![]() |
سلام .
من نیز برای ارسال از روش POST استفاده می کنم . اما در صفحه URL متغیرهای ارسالی را نمی شناسد . کد مورد استفاده را هم می گذارم لطفاً مشکل کار من را بگویید : کد ایجاد XMLhttpRequest : کد:
function getHttp()
{
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
}
}
return xmlHttp;
}
کد:
var httpData=getHttp();
function AnswerData()
{
if(httpData.readystate==4)
{
if (httpData.status == 200)
alert(httpData.responseText);
//eval(what);
else
alert('There was a problem retrieving the XML data: ' +httpData.responseText);
}
کد:
function sendData()
{
stData='Data=1&MyName='+txtName.value+';
httpData.open('POST','MyWeb/InsertPage.php', false);
httpData.onreadystatechange = AnswerData;
httpData.setRequestHeader('Content-Type', 'application/x-www-formurlencoded; charset=UTF-8;');
httpData.send(stData);
}
__________________
منتظرم .... در انتظاری سبز . « روزی می آید »
معرفی کمی از کارهام و یک سری مطالب مرتبط برنامه نویسی
سايت حامي سبز قومس آگهي استخدام روزنامه هاي كثير الانتشار |
|
|
|
|
|
#9 |
|
کاربر جدید
![]() تاریخ عضویت: مهر 1386
پست: 11
تشکرها: 0
0 بار تشکر شده در 0 پست
|
سلام.ببخشید من می خوام با آژاکس و php و javascript کار کنم .این کدهای بالا مربوط به چه زبانی است؟ میشه مثالی از ثبت کردن در mysql (نرم افزار wamp)را برای ما بزنید.
ممنون. |
|
|
|
|
|
#10 |
|
کاربر دائمی
![]() |
wamp یا xamp یا easyPHP هیچ فرقی ندارند .
من خودم نسبت به اهمین پروژه به ترتیب از prototypr و mootools استفاده می کنم که اینجور دردسر هارو هم نداره . |
|
|
|
![]() |
| بوک مارک کردن این تاپیک |
| کاربرانی که این تاپیک را مشاهده میکنند: 1 (0 کاربران و 1 مهمان) | |
| ابزار های تاپیک | |
| طریقه نمایش | |
|
|
تاپیک های مشابه
|
||||
| نام تاپیک | ایجاد کننده تاپیک | تالار | پاسخ | آخرین پست |
| سایت مفید درباره ASP.NET ajax , ajax control toolkit | reza_62 | برنامه نویسی Web با استفاده از ASP.NET | 0 | یک شنبه 14 مرداد 1386 17:47 عصر |
| Request در ASP.NET | safari123 | برنامه نویسی Web با استفاده از ASP.NET | 2 | سه شنبه 21 آذر 1385 07:36 صبح |
| Urgent Request | am12622 | برنامه نویسی Web با استفاده از ASP.NET | 3 | یک شنبه 20 شهریور 1384 05:45 صبح |
| انواع request ها | PrinceDotNet | برنامه نویسی Web با استفاده از ASP.NET | 2 | یک شنبه 05 تیر 1384 14:15 عصر |
| New request | Seiied Salar | گفتگو با مسئولین سایت، درخواست و پیشنهاد | 3 | جمعه 16 اردیبهشت 1384 23:54 عصر |