selfstarter

ajaxForm jquery 예제 본문

Web/Javascript

ajaxForm jquery 예제

selfstarter 2020. 6. 15. 11:13

ajaxForm jquery 예제

로컬에서는 실행이 되지 않는다. CORS 정책에 의해 차단되었다고 나온다

from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.1.1.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script>
	$(function(){
	
		$('#form').on('click', function(){
			$('#form').attr('action', './test.php').attr('method', 'post').ajaxForm({
				beforeSubmit: function(data, form, option) {
					console.log('beforeSubmit');
				},
				uploadProgress : function(event, position, total, percentComplete) {
					console.log('uploadProgress');
				},
				success : function(response, status) {
					console.log('success');
				},
				error : function(req, stat, err) {
					console.log('error');
				},
			}).submit();
		});		
	});
</script>
<style type="text/css">
</style>
</head>
<body>
<form id="form">
	Name: <input type="text" name="name" />
	Self introduce: <textarea name="introduce"></textarea>
	<input type="submit" value="ok" />
</form>
</body>
</html>

'Web > Javascript' 카테고리의 다른 글

JavaScript bind 사용법  (0) 2020.07.20
Javascript 다음 년도와 달 구하기  (0) 2020.06.17
Javascript copy paste 복사 붙여넣기 방지  (0) 2020.06.01
javascript escape  (0) 2020.05.28
Jquery input 비었는지 체크  (0) 2020.01.06
Comments