[jQuery] ajax prototype

javascript 2013. 4. 17. 14:42

원래 Jquery 만 쓰는데 간혹 Prototype로 짜여진 소스들을 보면 대부분의 기능을 사용하지 못한다. 
Jquery와 Prototype는 그 사용방법이 다르며 가장 중요한 점은 서로 충돌이 일어난다는 것이다. 
라엘이는 AJAX를 써야만 했고 Prototype AJAX 코드를 찾아내었다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
     
   var url = '/proc/send_friend';
 
  
 
    var myAjax = new Ajax.Request(url,
 
        {
 
            method: 'post',
 
            parameters: {'m_friend_id':str},
 
            onSuccess: parse_result_sendfriend//,
 
            //onFailure: function() { alert('HTML을 받아오지 못했습니다.');}
 
        }
 
    );


콜백함수

1
2
3
4
function parse_result_sendfriend(result){
var dataobj = decodeURIComponent(result.responseText);
        alert(dataobj);
}


참고로 Jquery Ajax코드

1
2
3
4
5
6
7
8
9
$.ajax({
    type: 'post',
    url: '/proc/send_friend',
    data: 'm_friend_id='+str,
    contentType: "application/x-www-form-urlencoded; charset=utf-8",
    success: function(result) {
        parse_result_sendfriend(result);
    }
});


콜백함수는 prototype와 같다.


참고 : https://lael.be/314

Posted by airlueos
,