jquery를 처음 사용합니다. html과 jquery를 사용하여 http://www.webservicex.net/geoipservice.asmx?op=GetGeoIP의 웹 서비스를 사용하려고합니다. 나는 다음과 같은 코드를 작성했다 :jquery를 사용하여 웹 서비스를 사용하려고 할 때 오류가 발생했습니다.
<!DOCTYPE html>
<page language ="html" validateRequest="false">
<html>
<head>
<title>Hello There</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> type="text/javascript" > </script>
</head>
<body>
<div>
IPAddress: <input type="text" name="id" id="theId"/>
<br />
<button id="getRemoteResponseBt">Get remote response</button>
</div>
<script>
var url='http://www.webservicex.net/geoipservice.asmx?op=GetGeoIP';
var dataMessage=
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<GetGeoIP xmlns="http://www.webservicex.net/"> \
<IPAddress>+theId.val()+</IPAddress> \
</GetGeoIP> \
</soap:Body> \
</soap:Envelope>';
$("#getRemoteResponseBt").click(function() {
$.ajax({
url: url,
dataType: "xml",
data: dataMessage,
processData: false,
contentType: "text/xml; charset=\"utf-8\"",
success: function(text) {
var xml = $(text);
var id = xml.find('IP').text();
var name = xml.find('CountryName').text();
var code = xml.find('CountryCode').text();
alert("Result:" + id +name+code);
},
error:function (xhr) {
alert(xhr.responseText+"Error");
}
});
return false;
});
</script>
</body>
</html>
그러나 내가 버튼을 클릭 할 때마다 에러가 난다. 아무도 코드 작동에 도움을 줄 수 있습니까? 도메인에서 도메인 간 게시물을 시도 http://www.webservicex.net/geoipservice.asmx?op=GetGeoIP
* 정확히 * 오류가 있습니까? – deceze
빠른 답장을 보내 주셔서 감사합니다. 경고에서 '정의되지 않은'오류가 발생합니다. 이 코드를 html 파일로 실행하여 확인할 수 있습니다. – user3181494
성공 함수가 호출 되었습니까? 아니면 오류 기능? 텍스트의 내용은 무엇입니까? 'xml'의 내용? 'id'의 내용? '이름'? '코드'? – Ishtar