코드 사본은 다음과 같습니다.
<div id = "oid"> </div>
<script type = "text/javaScript">
// 항목 번호를 가져옵니다
$ .ajax ({
URL : "http://192.168.1.191/h.ashx",
유형 : "get",
데이터 유형 : 'JSONP',
// JSONP의 값을 사용자 정의합니다. JSONCALLBACK을 사용하는 경우 서버쪽에는 JSONCALLBACK의 값에 해당하는 객체를 반환해야합니다.
JSONP : 'JSONCALLBACK',
// 전달 될 매개 변수가 전달되지 않으면 작성해야합니다.
데이터 : null,
타임 아웃 : 5000,
// JSON 유형으로 돌아갑니다
ContentType : "Application/JSON; UTF-8",
// 서버 세그먼트에서 반환 된 객체에는 이름과 openID가 포함되어 있습니다.
성공 : 기능 (결과) {
document.getElementById ( 'oid'). innerText = result.name+":"+result.openid;
},
오류 : 함수 (jqxhr, textstatus, errorthrown) {
경고 (TextStatus);
}
});
</스크립트>
서버 H.ASHX
코드 사본은 다음과 같습니다.
< %@ webhandler language = "c#"class = "h" %>
시스템 사용;
System.Web 사용;
공개 클래스 H : ihttphandler {
public void processRequest (httpcontext context) {
context.response.contentType = "Text/Plain";
문자열 result = context.request.queryString [ "JSONCALLBACK"] + "({/"name/":/"테스트 번호 IS/",/"OpenID/":/"123456789/"});
context.response.clear ();
context.response.write (결과);
context.response.end ();
}
공개 bool issusable {
얻다 {
거짓을 반환합니다.
}
}
}