jQuery.ajax()를 이용한 페이지 실행

JAVASCRIPT 2010. 12. 21. 16:04 Posted by Dayis
1. 데이터 직접 입력
$.ajax({
type: "POST",
url: "some.asp",
data: "name=John&location=Boston",
success: function(msg){
if (msg=="Done"){
alert( "Data Saved: " + msg );
}
}
});

참조 URL : http://api.jquery.com/jQuery.ajax/

2. FORM 전송
var string = $("form[name=폼네임]").serialize();
$.ajax({   
type: "POST",  
url: "form_proc.asp",   
data: string,   //&a=xxx 식으로 나옴
success: function(msg){
//메세지에 따른 처리
}
});

※ <textarea>의 엔터를 적용하기 위해서는 Replace 함수를 적용.
data: "content="+document.frmTest.content.value.replace(/\n/g,"<br/>"),



'JAVASCRIPT' 카테고리의 다른 글

jQuery 스크롤 페이징  (0) 2011.03.14
jQuery로 ajax실행 중 로딩이미지  (0) 2010.12.22
JQuery select box  (0) 2010.12.20
jquery 오류  (0) 2010.12.09
jquery : 셀렉터  (0) 2010.12.06

JQuery select box

JAVASCRIPT 2010. 12. 20. 15:02 Posted by Dayis

jQuery로 선택된 값 읽기
$("#select_box option:selected").val();
$("select[name=name]").val();

jQuery로 선택된 내용 읽기
$("#select_box option:selected").text();

선택된 위치
var index = $("#test option").index($("#test option:selected"));

-------------------------------------------------------------------

// Add options to the end of a select
$("#myselect").append("<option value='1'>Apples</option>");
$("#myselect").append("<option value='2'>After Apples</option>");

// Add options to the start of a select
$("#myselect").prepend("<option value='0'>Before Apples</option>");

// Replace all the options with new options
$("#myselect").html("<option value='1'>Some oranges</option><option value='2'>More Oranges</option><option value='3'>Even more oranges</option>");

// Replace items at a certain index
$("#myselect option:eq(1)").replaceWith("<option value='2'>Some apples</option>");
$("#myselect option:eq(2)").replaceWith("<option value='3'>Some bananas</option>");

// Set the element at index 2 to be selected
$("#myselect option:eq(2)").attr("selected", "selected");

// Set the selected element by text
$("#myselect").val("Some oranges").attr("selected", "selected");

// Set the selected element by value
$("#myselect").val("2");

// Remove an item at a particular index
$("#myselect option:eq(0)").remove();

// Remove first item
$("#myselect option:first").remove();

// Remove last item
$("#myselect option:last").remove();

// Get the text of the selected item
alert($("#myselect option:selected").text());

// Get the value of the selected item
alert($("#myselect option:selected").val());

// Get the index of the selected item
alert($("#myselect option").index($("#myselect option:selected")));

// Alternative way to get the selected item
alert($("#myselect option:selected").prevAll().size());

// Insert an item in after a particular position
$("#myselect option:eq(0)").after("<option value='4'>Some pears</option>");

// Insert an item in before a particular position
$("#myselect option:eq(3)").before("<option value='5'>Some apricots</option>");

// Getting values when item is selected
$("#myselect").change(function() {
alert($(this).val());
alert($(this).children("option:selected").text());
});

'JAVASCRIPT' 카테고리의 다른 글

jQuery로 ajax실행 중 로딩이미지  (0) 2010.12.22
jQuery.ajax()를 이용한 페이지 실행  (0) 2010.12.21
jquery 오류  (0) 2010.12.09
jquery : 셀렉터  (0) 2010.12.06
jquery : 속도, 페이드인, 애니메이션  (0) 2010.12.06

jquery 파일 업로드

ASP 2010. 12. 10. 18:43 Posted by Dayis

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>비동기 파일업로드 (www.hanji.pe.kr)</title>
<link href="/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript">
<!--
//ajax오류시 메세지 나오게함
$(document).ajaxError(function(info,xhr){
 if(xhr.status==500)
 alert("데이터 저장시 오류가 발생하였습니다.");
});

//파일전송 후 콜백 함수
function FileuploadCallback(data,state){
 if (data=="error"){
  alert("파일전송중 오류가 발생하였습니다.\n다시한번 시도해주세요.");
  //location.reload();
  return false;
 }
 alert("파일전송이 완료되었습니다.");
}

//비동기 파일 전송
$(function(){
 var frm=$('#frmFile');
 frm.ajaxForm(FileuploadCallback);
 frm.submit(function(){return false; });
});

// 파일업로드 이벤트
function FileUpload(){
 if(!$("#Filename").val()){
 alert("파일을 선택하세요.");
 $("#Filename").focus();
 return;
 }

 //파일전송
 var frm;
 frm = $('#frmFile');
 frm.attr("action","./ajax_fileupload.asp");
 frm.submit();
}
-->
</script>
</head>
<body>
<div style="width:350px">
<form id="frmFile" name="frmFile" method="post" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="1"  id="TableSt01"  class="row" style="width:350px">
<tr><th><h2>파일을 선택하세요.</h2></th></tr>
<tr><td>
 <input type="file" size="30" name="Filename" id="Filename" />
 <input type="button" class="btn menu" value="확인" onclick="FileUpload();" />
</td></tr>
</table>
</form>
</body>
</html>

'ASP' 카테고리의 다른 글

ASP 입력값 Replace (따옴표, 작은따옴표..)  (0) 2013.05.01
ASP 파라메터 컨트롤 함수  (0) 2012.01.09
구글맵  (0) 2010.12.09
구글맵 API Key 생성 URL  (0) 2010.12.01
ASP 배열을 자바스크립트 배열로 변경  (0) 2010.12.01