I have a CentOS 7 server hosting an internal webpage. On my webpage I have a button #test1
once clicked the test.js
should execute. test.js
should make an ajax call to send some XML to my Cisco phone for it to be executed.
I can run a CURL from my server and it works.
curl -H "Content-Type: text/xml" -d @test1.xml -X POST http://username:password@10.0.0.130/CGI/Execute
Where text1.xml contains
XML=<CiscoIPPhoneExecute><ExecuteItem URL="Dial:12345678,,,,,6020197#,,,,,,,,,,,,,,,,,#"/></CiscoIPPhoneExecute>
Why when I try to run it as a script doesn't it work? I am seeing the following errors.
Uncaught ReferenceError: $ is not defined
document root
/var/www/mysite.com/public_html
css index.html js
HTML - index.html
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<meta content="noindex, nofollow" name="googlebot">
<script src="./js/jquery-git.js" type="text/javascript"></script>
<script src='./js/test.js'></script>
<link rel="stylesheet" type="text/css" href="./css/style.css">
<title>Auto Bridge Opener</title>
</head>
<body>
<button name="Log" type="submit" id="test1">Primary Bridge</button></form>
CSS - style.css
JS - test.js
$(document).ready(function() {
$('#test1').on('click', function(e) {
e.preventDefault();
var btn = $(e.target);
btn.attr("disabled", "disabled"); // disable button
$.ajax({
type: "POST",
url: "http://username:password@10.0.0.130/CGI/Execute",
dataType: "xml",
contentType: "application/xml",
data: "<CiscoIPPhoneExecute><ExecuteItem URL='Dial:12345678,,,,,6020197#,,,,,,,,,,,,,,,,,#'/></CiscoIPPhoneExecute>",
success: function (res) {
alert("XML: it works!");
},
error: function (res) {
alert("XML: not working! " + res.statusText);
}
});
});
});
There maybe some issue with you code: 1 For the $ is not defined
,you should make sure the <script src="./js/jquery-git.js" type="text/javascript"></script>
not got a 404
,and the jquery-git.js
is a correct jQuery library. 2 The ajax do not support cross-domain
, so you phone and server should has the same domain.