var theWorker = new Worker('workerFile.js')
To listen for it:
theWorker.addEventHandler('message',function(event){
//Grab the result and do something with it
process(event.data)
});
To call the function defined in the web worker, we pass the arguments to the postMessage method of the worker object
theWorker.postMessage(arguments)
addEventHandler('message',function(event){
//The arguments from postMessage are held in event.data
var value = doBigCalcuation(event.data)
//Again post message is used to pass data
postMessage(value)
})
%load 'js/primes.js'
%%html
<html>
<head>
<style>
p#primes {width:800px;word-wrap: break-word;}
</style>
<script>
var primeWorker = new Worker('js/primes.js')
var primes = [];
primeWorker.addEventListener('message',function(event){
primes.push(event.data)
document.querySelector("#primes").innerHTML = primes.join(", ")
})
primeWorker.postMessage([100000,1000000])
</script>
</head>
<body>
<p id="primes"></p>
</body>
</html>
var theRequest = new XMLHttpRequest();
theRequest.open('METHOD','location',Asynchronous?)
theRequest.send(ParametersObject)
theRequest.addEventListener('load',function(){
if(theRequest.stauts === 200){
doSomething(theRequest.responseText)
}
}
%%html
<html>
<head>
<script>
var theRequest = new XMLHttpRequest()
var typeAhead = document.querySelector("#typeAhead")
theRequest.addEventListener('load',function(){
if(theRequest.status === 200){
typeAhead.value = theRequest.responseText
}
})
typeAhead.addEventListener("keyup",
function(){
theRequest.open('GET','http://www.csee.umbc.edu/~bwilk1/ajaxExample1.php?q=' + typeAhead.value ,true)
theRequest.send(null)
})
</script>
</head>
<body>
<input type="text" class="input" id="typeAhead"/>
</body>
</html>
{
"property1":val1,
.
.
.
"propertyN":[ anArray1, anArray2, anArray3 ]
}
<api batchcomplete="">
<continue gapcontinue="Programming_language_for_Computable_Functions" continue="gapcontinue||"/>
<query>
<pages>
<page _idx="23015" pageid="23015" ns="0" title="Programming language"/>
<page _idx="36706283" pageid="36706283" ns="0" title="Programming language-independent"/>
<page _idx="23521" pageid="23521" ns="0" title="Programming language/Timeline"/>
<page _idx="23523" pageid="23523" ns="0" title="Programming language/assembly"/>
<page _idx="20828640" pageid="20828640" ns="0" title="Programming language C"/>
<page _idx="43277179" pageid="43277179" ns="0" title="Programming language comparisons"/>
<page _idx="33500129" pageid="33500129" ns="0" title="Programming language compiler"/>
<page _idx="2848168" pageid="2848168" ns="0" title="Programming language design"/>
<page _idx="18073370" pageid="18073370" ns="0" title="Programming language dialect"/>
<page _idx="30873250" pageid="30873250" ns="0" title="Programming language error codes"/>
</pages>
</query>
</api>
"batchcomplete": "",
"continue": {
"gapcontinue": "Programming_language_for_Computable_Functions",
"continue": "gapcontinue||"
},
"query": {
"pages": {
"23015": {
"pageid": 23015,
"ns": 0,
"title": "Programming language"
},
"36706283": {
"pageid": 36706283,
"ns": 0,
"title": "Programming language-independent"
},
"23521": {
"pageid": 23521,
"ns": 0,
"title": "Programming language\/Timeline"
},
"23523": {
"pageid": 23523,
"ns": 0,
"title": "Programming language\/assembly"
},
"20828640": {
"pageid": 20828640,
"ns": 0,
"title": "Programming language C"
},
"43277179": {
"pageid": 43277179,
"ns": 0,
"title": "Programming language comparisons"
},
"33500129": {
"pageid": 33500129,
"ns": 0,
"title": "Programming language compiler"
},
"2848168": {
"pageid": 2848168,
"ns": 0,
"title": "Programming language design"
},
"18073370": {
"pageid": 18073370,
"ns": 0,
"title": "Programming language dialect"
},
"30873250": {
"pageid": 30873250,
"ns": 0,
"title": "Programming language error codes"
}
}
}
}
var obj = eval("(" + json + ")")
var obj = JSON.parse(json)
%%html
<html>
<head>
<script>
var wikiRequest = new XMLHttpRequest()
wikiRequest.addEventListener('load',
function(){
if(theRequest.status === 200){
var response = JSON.parse(wikiRequest.responseText)
var pages = response.query.pages
for(page in pages){
document.querySelector("#wikiResults").insertAdjacentHTML('beforeend',
"<li>" + pages[page].title + "</p>")
}
}
})
document.querySelector('#wikiSearch').addEventListener('input',
function(){
wikiRequest.open('GET',"https://en.wikipedia.org/w/api.php?action=query& " +
"generator=allpages&gaplimit=5&format=json&gapfrom=" +
document.querySelector("#wikiSearch").value)
wikiRequest.setRequestHeader('Api-User-Agent', 'UBMC 331 Class Example/1.0 (bryan.wilkinson@umbc.edu)' );
wikiRequest.setRequestHeader("Origin", "http://localhost:8888/notebooks/Lecture20.ipynb");
wikiRequest.send()
})
</script>
</head>
<body>
<input type="text" id="wikiSearch"/>
<ul id="wikiResults">
</ul>
</body>
</html>
//Selects all paragraph elements
$('p')
//Selects all elements of class highlight
$('.highlight')
$(selector).on(eventType,
function(event){
})
%%html
<html>
<head>
<script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
<script>
$('p').on('click',function(){
this.style.background = "green"
})
</script>
</head>
<body>
<div class="contain2">
<p> A Paragraph</p>
<p> A Second Paragraph</p>
<p> A Third Paragraph</p>
</div>
</body>
</html>
$.getJSON(url, parameters, function(json, status, jqueryRequestObject){
});