2014-06-11 1 views
0

첫 번째 Ajax 함수를 사용하여 두 번째 html select 요소를 생성하는 첫 번째 html select 요소가 있는데 제대로 작동합니다. 이 두 번째 html 요소는 세 번째 html select 요소를 생성하지만 세 번째 선택기 생성을 위해이 코드를 수행하면 작동하지 않습니다. 누구든지 나를 도울 수있게 만들었습니까? jquery를 사용하여 이전 선택된 값으로 html select 요소를 생성합니다.

$("#SystemNameSelection").on('change',function() 
{ 
    var SystemName = $("#SystemNameSelection").text(); 
    if (SystemName === "Value1") { 
     $.ajax({ 
     url:"MyFile1.php", 
     success:function(result) { 
      $("#MyElementToPutTheSelector").html(result); 
     } 
     }); 
    } 
    else if (SystemName === "Value2") { 
     $.ajax({ 
     url:"MyFile2.php", 
     success:function(result) { 
      $("#MyElementToPutTheSelector").html(result); 
     } 
     }); 
    } 
    else if (SystemName === "Value3") { 
     $.ajax({ 
     url:"MyFile3.php", 
     success:function(result) { 
      $("#MyElementToPutTheSelector").html(result); 
     } 
     }); 
    } 
}); 

Myfile1, myfile2가와 MyFile3

세 가지 HTML을 선택 요소를 포함 : 여기

는 코드입니다. .change() 메서드로 시도해 보았지만 작동하지 않았습니다.

+2

당신은 아마 이것과 함께 몇 가지 html을 첨부해야합니다. 그리고 아마 jsFiddle. – MikeWu

+0

브라우저 개발자 도구를 사용하고 네트워크 요청을 확인하십시오. 전송 된 내용과 AJAX 요청에 반환되는 내용을 볼 수 있어야합니다. 문제가있는 쪽을 알려줍니다. – StaticVoid

+0

show html 충분하지 않습니다. –

답변

0

시도해보십시오. 최근 버전의 jQuery를 사용하고 있는지 확인하십시오.

$("#SystemNameSelection").on('change',function() 
{ 
    var SystemName = $("#SystemNameSelection").text(); 

    switch (SystemName) { 
     case "Value1": 
      var myUrl = "MyFile1.php"; 
     case "Value2": 
      var myUrl = "MyFile2.php"; 
     case "Value1": 
      var myUrl = "MyFile3.php"; 
    } 

    $.ajax({url:myUrl, success:function(result) 
     { 
     $("#MyElementToPutTheSelector").html(result); 
     } 
    }); 
}); 
0

오늘은이 코드를 시험해보고 올바르게 작동합니다.

$("#SystemNameSelectionDiv").ready(function(){ 
$("#SystemNameSelection").change(function() 
{ 
    var SystemName = $("#SystemNameSelection").text(); 
    if (SystemName === "Value1") { 
     $.ajax({ 
     url:"MyFile1.php", 
     success:function(result) { 
      $("#MyElementToPutTheSelector").html(result); 
     } 
     }); 
    } 
    else if (SystemName === "Value2") { 
     $.ajax({ 
     url:"MyFile2.php", 
     success:function(result) { 
      $("#MyElementToPutTheSelector").html(result); 
     } 
     }); 
    } 
    else if (SystemName === "Value3") { 
     $.ajax({ 
     url:"MyFile3.php", 
     success:function(result) { 
      $("#MyElementToPutTheSelector").html(result); 
      } 
     }); 
    } 
}); 
}); 
+0

#SystemNameSelectionDiv는 HTML div 요소이고 #SystemNameSelection은 HTML select 요소입니다. – FredS104

관련 문제