jquery를 사용하여 서버 측 메서드를 호출하려고하는데, 클라이언트 측에서 동적으로 생성 된 텍스트 상자의 textchange 이벤트에서이 ID를 가져 오는 방법을 알지 못합니다. 누군가 내가이 일을하도록 도울 수 있습니까? 다음과 같이 사용하여 스크립트 메신저는 다음과 같습니다jquery를 사용하여 서버 측 메소드를 호출하는 방법은 무엇입니까?
<script type="text/javascript">
$(init);
function init() {
$('#test').droppable( //Div Control where i'll be dropping items
{
drop: handleDropEvent
});
$('a').each(function(idx, item) {
$(item).draggable({ cursor: 'move', helper: 'clone' })
});
}
function handleDropEvent(event, ui) {
var draggable = ui.draggable;
document.getElementById('test').innerHTML += addColumn(draggable.attr('text')) + '<br>';
}
$('.textChangeClass').live('change', function() {
/* Evokes on the text change event for the entire textboxes of class .textChangeClass. Is it possible to specify the dynamic textbox generated @ clientside here? (like for e.g. : $('#mytextbox').click(function()) */
$.ajax({
type: "POST",
url: "Webtop.aspx/ServerSideMethod", //This is not getting called at all.
data: "{'param1': AssignedToID}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function(msg) {
alert("From Server");
}
})
});
});
function addColumn(column) {
var iHtml;
//This is how i'm generating the textboxes along with a checkbox bound by a div.
iHtml = '<div id="dv' + column + '" width="100px;" height="20px;" padding: "0.5em;"> ' + '<span title="ToolTipText">' + '<input type="checkbox" id="cb' + column + '" value="' + column + '" /> <label for="cb' + column + '">' + column + '</label></span><input class="textChangeClass" type="text" id="aln' + column + '"> </div>';
return iHtml
}
</script>
오류 응답 기능을 youar ajax 호출에 추가했습니다. 내 대답은 –
입니다. 문제의 해결책은 클라이언트 측 코드 (JavaScript 코드)뿐만 아니라 서버 코드에도 의존합니다. 나를 위해 당신이 어떻게 서버 방법을 구현하는 절대적으로 불분명하다.가장 쉬운 방법은 ASMX 웹 서비스 또는 WCF 일 것이지만이 경우 url은'Webtop.asmx/ServerSideMethod' 또는'Webtop.svc/ServerSideMethod'이어야합니다. 질문에 서버 코드에 대한 추가 정보를 포함 시키거나 코드 조각을 포함 시키십시오. – Oleg