问题
I'm new to AJAX and am trying to access our WSDL database through the following code. When I run it, the Firefox debugger says "[10:27:42.805] ReferenceError: $ is not defined @ http://newsite.wrapcompliance.org/ajaxtest.html:14": Thoughts?
<h3>jQuery Test</h3>
<script type="text/javascript">
function callService()
{
$.ajax
({
url: "http://newsite.wrapcompliance.org/FactoriesWS.wsdl",
type: "POST",
dataType: "xml",
data: {"countryCd":"BGD"},
contentType: "text/xml; charset=\"utf-8\"",
success: onSuccess,
error: onError
});
return false;
}
function onSuccess(data, status)
{
alert("It worked!!");
}
function onError(request, status, error)
{
alert("It didn't work!!!");
}
</script>
<form method="post" action="">
<input type="button" value="Do it now!!" onclick="callService(); return false"/>
</form>
</body>
</html>
回答1:
Your error is the result of not actually having jQuery present. I looked at your sample site and jquery threw a 404 in the net tab of firebug, meaning it wasn't found. Make sure it's pointing to the correct local directory. Currently it is looking in http://newsite.wrapcompliance.org/jquery-1.9.1.min.js
That said, calling the wsdl itself will most likely return the xml summary page of the wsdl, not an exposed service. I'd recommend wrapping your exposed wsdl endpoints in restful services. I've done this multiple times with WebAPI RESTful services and it's always taken a huge chunk out of the headache.
来源:https://stackoverflow.com/questions/15526436/problems-accessing-wsdl-with-ajax