Novice here, trying to demonstrate the value of client side rest operations to teammates as they rely on scripts and python. Not sure if it's the fact I'm using numbers for the value attribute or if I'm referencing the getelementbyid wrong. It's honestly probably none of those things :)
I've tried to explicitly reference an id assigned to the IP address in the getelementbyid for MakeUrl but it still fails. I also thought for a second it was null becasue it was using the default value but I commented it out and I still got the error.
Error:
Uncaught TypeError: Cannot read property 'value' of null (MakUrl Function)
function makeUrl() {
var ip = document.getElementById("apigatewayip").value;
return "https://" + ip + "/api/v0/sessions"
};
function createSession(_url) {
return $.ajax({
"url": _url,
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({
"gatewayVersion": "1.00.1.15"
}),
});
}
createSession(makeUrl());
createSession(makeUrl()).success(function() {
});
<h1>Making AJAX Rest Calls</h1>
<div class="custom-select" style="width:200px;">
<select name="selectip" id="apigatewayip" onchange="makeUrl">
<option value="" disabled selected>API Gateway IP</option>
<option value="169.254.1.10">169.254.1.10</option>
</select>
<button onclick="createSession">Submit</button>
</div>
idvalues within the DOM. Also note thatonchange="makeUrl"is redundant.createSessiontwice in the code here. I'd remove the first call and change the second to usetheninstead ofsuccess, sincesuccesshas been deprecated.onchangebeing redundant. The only way OPs code will run is if he callsmakeUrl()directly, which is what the example does - and it works.$("#apigatewayip").on("change",makeUrl)or$("#apigatewayip").on("change",function)( { makeUrl() })- you are missing the () when you call but which you need to leave out when assigning