그래서 나는 아약스와 함께 jquery에 좀 새로운입니다. 기본적으로이 페이지는 http 게시물을 보내고 서버 쪽 dll은 json 형식으로 페이지에 응답을 씁니다. 이 응답을 처리하는 방법을 파악하려고합니다. 지금까지 웹 사이트에 도착하여 모든 정보를 입력하고 제출을 누르면 iis 웹 서버 페이지에 게시되고 요청을 처리 한 다음 json 형식으로 serialize하고 HttpContext.Current.Response.Write 페이지로 돌아갑니다. 이제 페이지에 json 형식으로 텍스트가 표시됩니다.서버에서 jQuery 아약스 프로세스 요청
이 응답을 어떻게 캡처하여 데이터로 처리하고 더 읽기 쉬운 형식으로 화면에 표시 할 수 있습니까? 모든 페이지에서이 isn jquery/ajax 형식을 수행해야합니다.
아래는 완전히 html 코드입니다.
<HTML>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
// variable to hold request
var request;
// bind to the submit event of our form
$("#frmLookup").submit(function(event){
// abort any pending request
if (request) {
request.abort();
}
// setup some local variables
var $form = $(this);
// let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
// serialize the data in the form
var serializedData = $form.serialize();
// let's disable the inputs for the duration of the ajax request
$inputs.prop("disabled", true);
// fire off the request to /form.php
request = $.ajax({
url: "http://server1/RWebService/users",
type: "post",
data: serializedData
});
// callback handler that will be called on success
request.done(function (response, textStatus, jqXHR, json){
// log a message to the console
console.write("HELLO WORLD");
});
// callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown){
// log the error to the console
console.error(
"The following error occured: "+
textStatus, errorThrown
);
});
// callback handler that will be called regardless
// if the request failed or succeeded
request.always(function() {
// reenable the inputs
$inputs.prop("disabled", false);
});
// prevent default posting of form
event.preventDefault();
});
</script>
</head>
<body>
Look up user
<form id="frmLookup" name="input" action = "http://server1/RWebService/users" method = "post" >
BWS HostName: <input type="text" name="wBWSHostName" value="foobar.com" />
<BR>
UserName: <input type="text" name="wBWSUserName" value="admin" />
<br />
Password: <input type="password" name="wBWSPassword" value="password"/>
<BR>
Lookup User: <input type="text" name="wUser" value="[email protected]"/>
<input type="submit" name="wLookup" value="Lookup" />
</form>
<div id="data">
</div>
</body>
</HTML>
예제를 제공 할 수 있습니까? 지금 모든 데이터는 페이지에 json 형식으로 표시됩니다. – user1158745