Thomas Murphy
Thomas Murphy

Reputation: 1468

Syntax Error in XMLHttpRequest Function

I'm not primarily JS, so I may be making a stupid here, apologies if that is the case.

In the code:

function loadeightoheightclap("http://thomasmurphydesign.com/dubstepclap.wav") {
var request = new XMLHttpRequest();
request.open('GET', "http://thomasmurphydesign.com/dubstepclap.wav", true);
request.responseType = 'arraybuffer';

request.onload = function() {
    context.decodeAudioData(request.response, function(buffer) {
        eightoheightclapbuffer = buffer;
    }, onError);
}
request.send();
}

The URL in that's the argument of function loadeightoheightclap is throwing a syntax error. It's a valid URL, and there's no syntax error when that URL is used as an argument of request.open later.

How do I need to modify the argument to remove the error?

Upvotes: 0

Views: 1152

Answers (1)

bfavaretto
bfavaretto

Reputation: 71939

Functions definitions should take a parameter name, not an actual value:

function loadeightoheightclap(url) { /* ... */ }

Your should only use a value when calling it:

loadeightoheightclap("http://thomasmurphydesign.com/dubstepclap.wav");

Then you can use that value by name inside the function:

request.open('GET', url, true);

Upvotes: 2

Related Questions