CI 묻고 답하기

제목 httpRequest.open 에러.. 좀 도와주세요 ㅜㅜ
글쓴이 vvshinevv 작성시각 2016/08/06 02:01:05
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 14414   RSS

안녕하세요 

코드이그나이터 책 사서 열심히 따라해보고 있습니다.

그런데 오타도 없고 몇번을 확인하고 구글링을 해봐도.. 답이 안나오는거같아서 

질문올립니다...

(혹시 또 허무한곳에서 답이 나올까봐 두렵긴 하네요..나름 5시간..동안 찾아보고 이것저것해봣는데..)

 

페이지는 232쪽부터 입니다. 

/include/js/httpRequest.js

function getXMLHttpRequest() {
	if(window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e1) { return null; }
		}
	} else {
		return null;
	}
}

var httpRequest = null;

function sendRequest(url, params, callback, method) {
	httpRequest = getXMLHttpRequest();
	var httpMethod = method ? method : 'GET';

	if(httpMethod != 'GET' && httpMethod != 'POST') {
		httpMethod = 'GET';
	}

	var httpParams = (params == null || params == '') ? null : params;
	var httpUrl = url;
	if(httpMethod == 'GET' && httpParams != null) {
		httpUrl = httpUrl + "?" + httpParams;
	}

	httpRequest.open(httpMethod, httpUrl, true);
	httpRequest.setRequestHeader(
		'Content-Type', 'application/x-www-form-urlencoded');

	httpRequest.onreadystatechange = callback;
	httpRequest.send(httpMethod == 'POST' ? httpParams : null);
}

요런식으로 작성을 햇구요..

controllers/ajax_board.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
* Ajax 처리 컨트롤러
*/
class Ajax_board extends CI_Controller {
	function __contruct() {
		parent::__contruct();
	}

	/**
	* Ajax 테스트
	*/
	public function test() {
		$this->load->view('ajax/test_v');
	}

	public function ajax_action() {
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';

		$name = $this->input->post("name");
		echo $name."님 반갑습니다!";
	}
}

 

그리고

views/ajax/test_v.php 

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
	<title>CodeIgniter</title>
	<!--<script type="text/javascript" src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>-->
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/sweetalert2/4.0.16/sweetalert2.min.css">

	<script type="text/javascript" src="/todo/include/js/httpRequest.js"></script>
	<script type="text/javascript">
		function server_request() {
			var csrf_token = getCookie('csrf_cookie_name');
			var name = "name=" + encodeURIComponent(document.ajax_test.names.value) + "&csrf_test_name=" + csrf_token;
			/**
			* @param url : 데이터를 전달하여 처리할 웹 서버 주소
			* @param name : 파라미터
			* @param callback : 콜백 함수 post방식으로 전소아고 처리가 끝나면 받은 데이터를 callback_hello에서 처리하란 뜻
			* @param 전송 방식
			*/
			sendRequest("http://localhost/todo/index.php/ajax_board/ajax_action", name, callback_hello, "POST"); // httpRequest.js에 있는 함수
		}

		function callback_hello() {
			if(httpRequest.readyState == 4) {
				if(httpRequest.status == 200) {
					var contents = document.getElementById("contents");
					contents.innerHTML = httpRequest.responseText;
				}
			}
		}

		function getCookie(name) {
			var nameOfCookie = name + "=";
			var x = 0;

			while(x <= document.cookie.length) {
				var y = (x + nameOfCookie.length);

				if(document.cookie.substring(x, y) == nameOfCookie) {
					if((endOfCookie = document.cookie.indexOf(";", y)) == -1)
						endOfCookie = document.cookie.length;

					return unescape(document.cookie.substring(y, endOfCookie));
				}

				x = document.cookie.indexOf(" ", x) + 1;

				if(x == 0)

				break;
			}

			return "";
		}
	</script>
	</head>
	<body>
		<div id="main">
			<form method="post" name="ajax_test">
				<label>이름</label>
				<div>
					<input type="text" name="names" value="웅파">
				</div>
				<div>
					<input type="button" onclick="server_request()" value="전송">
				</div>
			</form>
			<div id="contents"></div>
		</div>
	</body>
</html>

입니다. 그런데

자꾸 에러가

요런 에러가 발생이 되네요...

open 함수를 읽을 수없다는게.. 혹시 저와같은문제를 겪는분이나.. 해결하신분 도움좀 요청합니다!!

 다음글 코드이그나이터, XAMPP 객체 없음 문제 (1)
 이전글 공통적인 부분은 따로 빼서 만들고 싶습니다. (5)

댓글

변종원(웅파) / 2016/08/06 14:45:44 / 추천 0

js파일 위치 보세요. 아래 위치에 js파일이 존재하는지...

<script type="text/javascript" src="/todo/include/js/httpRequest.js"></script>

232페이지는 게시판 프로젝트라 todo와는 상관이 없습니다.

 

234 페이지 보시면 /bbs/include.... 라고 되어 있습니다.

vvshinevv / 2016/08/06 15:49:33 / 추천 0

흑흑 웅파님..

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

를 안썻네용... ㅜ_ㅜ... (흑흑...)

하.. 이런.. ㅠ_ㅠ!! 감사합니다 덕분에 확인다시하면서 해결됐네용!!

변종원(웅파) / 2016/08/08 10:10:02 / 추천 0
vvshinevv/ 저도 가끔 삽질이라 불리는 것을 합니다. 개발자의 숙명(?) 같은거죠. ^^