2012-08-10 2 views
0

이것은 내 자바 스크립트 코드입니다.아약스의 javascript 변수

$(\"img.agree\").click(function() 
    { 
    var follow_id = $(this).attr(\"id\"); 
    var user_id = $(\"img.user_id\").attr(\"id\"); 

    $.ajax({ 
    type: \"POST\", 
    url: \"/sys/follow.php\", 
    data: { 'follow_id': + follow_id, 'user_id': + user_id }, 
    success: function(html){} 
    }); 

    $(\"img.agree\"+follow_id).hide(); 
    $(\"img.notagree\"+follow_id).css('display','inline-block'); 
    }); 

    $(\"img.notagree\").click(function() 
    { 
    var follow_id = $(this).attr(\"id\"); 
    var user_id = $(\"img.user_id\").attr(\"id\"); 

    $.ajax({ 
    type: \"POST\", 
    url: \"/sys/dontfollow.php\", 
    data: { 'follow_id': + follow_id, 'user_id': + user_id }, 
    success: function(html){} 
    }); 

    $(\"img.notagree\"+follow_id).hide(); 
    $(\"img.agree\"+follow_id).css('display','inline-block'); 
    }); 

나는 모든 IMG 태그의 수와 같은 요청을 보낼 수 없습니다 아약스 요청 하나 특정 일 또는 클래스 = 'notagree의 $ 문자열' '$ 문자열을 동의'= 수업 후 고유 한 문자열을 사용합니다. 그러나 그것은 작동하지 않을 것이다. 내가 생각하는 문제는 + follow_id 또는 이와 비슷한 것이다.

+1

당신이 무엇을하고 있는지 이해하기 위해 여기에 충분한 정보가되지 않습니다 PHP에서이 제거 옹호 :

<html> <img id="agree1" class="agree" src"" /> <img id="notagree1" class="notagree" src"" /> </html> 

대응 JS는 것이다. 이 자바 스크립트를 출력하는 PHP 코드를 게시하여 완전한 컨텍스트를 볼 수 있습니다. –

+3

따옴표를 왜 이스케이프하고 있습니까? – Blowsie

+5

무엇이 문제입니까? – pankar

답변

0

이것을 자바 스크립트 파일로 옮겼습니다. 사용중인 PHP 변수가 없으므로 PHP로 생성 할 때 어떤 점도 보이지 않습니다. 또한 귀하의 HTML이 이와 비슷한 것처럼 보일 수도 있습니다.

<html> 
<img id="1" class="agree1" src"" /> 
<img id="1" class="notagree1" src"" /> 
</html> 

그런 경우 실제로 동일한 ID로 다른 요소가 없어야합니다. 나는 이런 것을 생각합니다.

$("img.agree").click(function() 
    { 
     var follow_id = /\d/.exec(this.id); //parse out the number you are looking for with a regex 
     var user_id = $("img.user_id").attr("id"); 

     $.ajax({ 
      type: "POST", 
      url: "/sys/follow.php", 
      data: { 'follow_id': + follow_id, 'user_id': + user_id }, 
      success: function(html){} 
     }); 

     $("#agree"+follow_id).hide(); 
     $("#notagree"+follow_id).css('display','inline-block'); 
    }); 

$("img.notagree").click(function() 
    { 
     var follow_id = /\d/.exec(this.id); //parse out the number you are looking for with a regex 
     var user_id = $("img.user_id").attr("id"); 

     $.ajax({ 
      type: "POST", 
      url: "/sys/dontfollow.php", 
      data: { 'follow_id': + follow_id, 'user_id': + user_id }, 
      success: function(html){} 
     }); 

     $("#notagree"+follow_id).hide(); 
     $("#agree"+follow_id).css('display','inline-block'); 
    }); 

을 그리고 다시, 나뿐만 아니라