Programming/Frontend
-
jquery ajax method 정리2014.03.12
-
jQuery multi redio button valid check2014.02.13
-
[ajax] JSONP CROSS SITE 응답 받기2014.02.12
-
jQuery에서 부모창 제어/접근(opener, parent)2014.02.11
-
jquery hover 효과2013.12.20
jquery ajax method 정리
2014. 3. 12. 09:53
반응형
$.ajax({
type: 'POST',
url: _url,
cache: false,
dataType: "json",
data: _data,
processData: true,
contentType: "application/json; charset=utf-8",
success: function(data, status){
},
error: function(request, status, error){
}
});
Name |
Value/Description |
파라메터는 한 개 이상의 name/value 쌍으로 표시 |
async |
Boolean 값 |
요청이 비동기식으로 처리되는지 여부를 나타냄 기본값은 true |
beforeSend(xhr) |
|
요청을 보내기 전에 실행되는 함수 |
cache |
Boolean 값 |
브라우저가 요청된 페이지를 캐싱해야 하는지 여부를 나타냄 |
| complete(xhr,status) | 요청이 완료됐을 때 실행되는 함수 | |
| contentType | 서버로 보내지는 데이터의 content-type 기본값은 “application/x-www-form-urlencoded" | |
| dataFilter(data,type) | XMLHttpRequest의 응답 데이터를 처리할 때 사용되는 함수 | |
| dataType | 서버 응답으로 받는 데이터 타입 | |
| error(xhr,status,error) | 요청이 실패했을 때 실행되는 함수 | |
| global | Boolean 값 | 요청에 대해 전역 AJAX 이벤트를 실행할 지 여부를 명시함 |
| jsonp | jsonp 요청에서 callback 함수를 오버라이딩하는 문자열 | |
| jsonpCallback | jsonp 요청에서 callback 함수 이름을 나타냄password | |
| password | HTTP 접근 인증(access authentication) 요청에 사용할 password를 나타냄 | |
| processData | Boolean 값 | 요청으로 보낸 데이터를 query string 형태로 변환할지 여부를 나타냄 기본값은 true |
| scriptCharset | 요청할 때의 charset을 나타냄 | |
| success(result,status,xhr) | 요청이 성공했을 때 수행되는 함수 | |
| timeout | 요청에 대해 로컬의 응답제한시간(timeout)을 밀리초로 나타냄 | |
| traditional | Boolean 값 | 파라미터 직렬화를 기존 방식으로 사용할 지 여부를 나타냄 |
| type | 요청 type(GET 혹은 POST)을 명시함 | |
| url | 요청을 보낼 URL을 나타냄 기본값은 현재페이지 | |
| xhr | XMLHttpRequest 오브젝트를 생성할 때 사용하는 함수 |
반응형
'Programming > Frontend' 카테고리의 다른 글
| [jQuery] each break/continue (0) | 2015.01.22 |
|---|---|
| [jQuery] loadingbar plugin (0) | 2014.09.19 |
| jQuery multi redio button valid check (0) | 2014.02.13 |
| [ajax] JSONP CROSS SITE 응답 받기 (0) | 2014.02.12 |
| jQuery에서 부모창 제어/접근(opener, parent) (0) | 2014.02.11 |
jQuery multi redio button valid check
2014. 2. 13. 11:01
반응형
개발을 하다보면 multi radio button에 대한 유효성 검증 로직을 사용할 경우가 있다.
특히 설문지 형태에 동적인 페이지에 대하여 선택값 검증을 할 경우가 종종 있던거 같아 작성해 본다.
jQuery each를 이용하여 3번에 for문이 돌아간다.
1 - Question 문항
2 - Question 문항 안에 소단위 문항
3 - radio button 목록
-Evaluation.aspx
<script>
$J(function() {
document.location.href = '#show';
$J('input:radio').addClass("vm");
var chkVal;
//등록
$J("#btnReg").click(function() {
var chkLen = 0;
var chkLen2 = 0;
$J("[id='tableExample']").each(function(i) {
chkVal = "N";
chkLen2 = 0;
$J(this).find("#trExample").each(function(j) {
chkVal = "N";
$J(this).find("input:radio").each(function() {
if ($J(this).is(":checked") == true) {
chkVal = "V";
}
});
if (chkVal != "V") {
alert((i + 1) + "번 문항의 " + (j + 1) + "번째 직원의 답변을 선택해주세요");
$J(this).find("input:radio")[0].focus();
return false;
} else if (chkVal == "V") {
chkLen2++;
}
});
if ($J(this).find("#trExample").length == chkLen2) {
chkLen++;
} else {
return false;
}
});
});
});
</script>
html 영역 Question No를 기준으로 for문이 돌고, 중첩으로 소문항 단위로 for문이 호출되는 구조
-Question.aspx
<asp:Repeater ID="rptQuestionList" runat="server" OnItemDataBound="rptQuestionList_OnItemDataBound">
<table id="tableExample">
<asp:Repeater ID="rptAnswerList" runat="server" OnItemDataBound="rptAnswerList_OnItemDataBound">
<tr id="trExample">
<input type="radio" class="vm" id="rdoExample1">
<input type="radio" class="vm" id="rdoExample2">
<input type="radio" class="vm" id="rdoExample3">
</tr>
</asp:Repeater>
</table>
</asp:Repeater>
반응형
'Programming > Frontend' 카테고리의 다른 글
| [jQuery] loadingbar plugin (0) | 2014.09.19 |
|---|---|
| jquery ajax method 정리 (0) | 2014.03.12 |
| [ajax] JSONP CROSS SITE 응답 받기 (0) | 2014.02.12 |
| jQuery에서 부모창 제어/접근(opener, parent) (0) | 2014.02.11 |
| jquery hover 효과 (0) | 2013.12.20 |
[ajax] JSONP CROSS SITE 응답 받기
2014. 2. 12. 18:23
반응형
front-end에서 외부 도메인과 통신할 경우 javascript에서 JSONP를 이용하여 ajax통신이 가능하다.
아래 간단한 예제를 활용해 보자.
javascript
$.ajax({
type : "GET",
dataType: "jsonp",
data: {id: "tttt"},
url: "http://www.test2.com/request",
success: function(data) {
$("#result").html(JSON.stringify(data));
},
error: function() {
alert("error");
}
});
java request
@RequestMapping(value = "/request", method = RequestMethod.GET)
public String request(@RequestParam String id, @RequestPrarm String callback) {
Map<string, string> paramMap = new HashMap<string, string>();
paramMap.put("id", id);
paramMap.put("result", "success");
String result = null;
ObjectMapper mapper = new ObjectMapper();
try {
result = mapper.writeValueAsString(paramMap);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);
return callback + "(" + result + ")";
}반응형
'Programming > Frontend' 카테고리의 다른 글
| jquery ajax method 정리 (0) | 2014.03.12 |
|---|---|
| jQuery multi redio button valid check (0) | 2014.02.13 |
| jQuery에서 부모창 제어/접근(opener, parent) (0) | 2014.02.11 |
| jquery hover 효과 (0) | 2013.12.20 |
| jQuery.noConflict() alias 사용 (0) | 2013.03.24 |
jQuery에서 부모창 제어/접근(opener, parent)
2014. 2. 11. 16:05
반응형
jQuery 자식 팝업 창에서 부모창 컨트롤
$(opener.document).find("#Form").attr("action","index.do").submit();
자식창 -> 부모창으로 값 전달하기
opener.document.getElementById("id").value="value"; //dom 객체로 제어
$("#id",opener.document).val("value"); // jQuery 방식 1
$("input[name=imgFile]", parent.document.body).val() // 방식 2
$(opener.document).find("#id").val("value"); //방식 3
opener.location.href="javascript:fun();"; //일반적인 방법
$(opener.location).attr("href","javascript:fun();"); //jQuery 이용반응형
'Programming > Frontend' 카테고리의 다른 글
| jQuery multi redio button valid check (0) | 2014.02.13 |
|---|---|
| [ajax] JSONP CROSS SITE 응답 받기 (0) | 2014.02.12 |
| jquery hover 효과 (0) | 2013.12.20 |
| jQuery.noConflict() alias 사용 (0) | 2013.03.24 |
| jQuery Selector 정리 (0) | 2013.03.24 |
jquery hover 효과
2013. 12. 20. 09:31
반응형
hover 처리
Untitled Document
반응형
'Programming > Frontend' 카테고리의 다른 글
| [ajax] JSONP CROSS SITE 응답 받기 (0) | 2014.02.12 |
|---|---|
| jQuery에서 부모창 제어/접근(opener, parent) (0) | 2014.02.11 |
| jQuery.noConflict() alias 사용 (0) | 2013.03.24 |
| jQuery Selector 정리 (0) | 2013.03.24 |
| 자바스크립트 textarea line 갯수 가져오기 (0) | 2013.03.22 |