2012-01-21 2 views
3

입력 필드 더미가있는 양식이 있습니다. 모든 필드와 함께 아약스 GET 요청을 만들고 싶습니다! 가장 쉬운 방법은 지금까지 데이터 객체에 대한 입력을 할당 같습니다

$('#myForm').find('input').each(function(index){ 
    myData = $.data($('#myForm'), $(this).attr('name'), $j(this).val()); 
}); 

... 다음은 아약스를 통해 펌프 :

$.ajax({ 
    type:"GET", 
    url: '/otherpage.php', 
    data = myData, 
    error(function(){}), 
    success(function(){}); 
}); 

그러나 물론이 작동하지 않습니다 ... $ _GET 변수가 otherpage.php에 나타나지 않으며, 콘솔에는 myData이 거대한 객체 거래라는 것을 보여줍니다.

어떻게 이런 식으로 아약스를 통해 데이터를 보냅니 까? 더 좋은 방법이 있습니까?

답변

6

를 사용하여 jQuery를 serialize(); 방법 :

$.ajax({ 
    type:"GET", 
    url: '/otherpage.php', 
    data = $('#myForm').serialize(), 
    error(function(){}), 
    success(function(){}); 
}); 

http://api.jquery.com/serialize/

+0

정말 쉽지 않은가? 나는 그것을 발견하지 못했다고 믿을 수 없다. 고마워. – emc

+0

probs가 없으니 기쁘다. 같은 문제가있는 경우 다른 사람들이 솔루션을 찾을 수 있도록 답변을 수락 한 것으로 표시하십시오. :) – SeanNieuwoudt

1
$.ajax({ 
    type:"GET", 
    url: '/otherpage.php', 
    data = $('#myForm').serialize(), 
    error(function(){}), 
    success(function(){}); 
}); 

희망 it'will 당신을 도와줍니다.

관련 문제