안녕하세요, 프로그래머는 과거에 나에게 매우 도움이되었으므로 여기서 다시 질문 할 것이라고 생각했습니다. 아마 간단한 수정 일 수도 있지만 JavaScript와 Ajax를 처음 사용합니다.JavaScript/Ajax : 숨겨진 필드 채우기
내가 작업 한 것은 텍스트 필드가 포커스를 잃었을 때 "LOCATION NOT FOUND"가 표시되지 않으면 responseText에 "AOCAX"가 기록된다는 것입니다. 이 responseText가있는 경우 양식 제출을 방해하는 것입니다. 숨겨진 필드의 값이 LOCATION NOT FOUND 인 경우 양식 제출을 방지하는 방법을 알고 있으므로 JavaScript를 사용하여 숨겨진 필드를 responseText로 채우는 것이 가장 쉬운 해결책 일 수 있다고 생각했습니다. 그게 효과가 있는지, 어떻게하는지에 대해서는 확실치 않습니다.
여기 내 현재 JS :
<script type="text/javascript">
<!--
function newXMLHttpRequest()
{
var xmlreq = false;
if (window.XMLHttpRequest)
{
xmlreq = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try
{
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2)
{
alert("Error: Unable to create an XMLHttpRequest.");
}
}
return xmlreq;
}
function getLocation(locationrouting)
{
var getLocation= newXMLHttpRequest(); // sending request
getLocation.open("GET", "/PP?PAGE=GETLOCATIONNAME&ROUTINGNUM=" + locationrouting, false);
getLocation.send(null); // getting location
var dv = document.getElementById("location_div");
if (getlocation.responseText === 'LOCATION NOT FOUND')
{
dv.style.color = "red";
}
else
{
dv.style.color = "black";
}
dv.innerHTML = getLocation.responseText;
}
//-->
</script>
여기 형태의 해당 부분 : 사전에
<form name="locationform" id="locationform" action="/PP?PAGE=POSTADDLOCATION" method="post">
<tr>
<td class="ajax_msg">
<div id="location_div">/div>
</td>
</tr>
<tr>
<td>
<div class="column1" id="locationrouting_div">
<p class="label_top">
*Routing Number</p>
<p class="field_top">
<input type="text" id="locationrouting" name="locationrouting" size="28" maxlength="9" onblur="getLocation(this.value);" /></p>
...
감사합니다!
동의했다. 하지만 제 고용주는 제가 프론트 엔드에서 그것을하기를 원합니다. 백 엔드에서 일하는 프로그래머는 내 상사이고, 그는 내게 솔루션을 찾아야합니다. – Spockrates
해결책은 JavaScript로 구현할 수 있습니까? 아니면 서버에서 구성해야합니까? – Spockrates
@ Spockrates 응답 텍스트가! == "LOCATION NOT FOUND"인 경우 다른 Ajax 요청을 보내고 양식을 제출하는 문제 일뿐입니다. –