Sending request from browser to ESP8266WebServer fails - xmlhttprequest

I have a server in my ESP8266-01. The ESP8266 is in softAP mode. ESP8266WebServer.h is used to create the server.
When I type 192.168.4.1/1/ in the browser, it returns a UI containing buttons. The buttons are generated from the following code:
addToBuffer("<div class=\"row\">");
for(i=1; i<5; i++) {
addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-primary\" id='btn_on");
addToBuffer(clientId);
addToBuffer(i);
if(i==1)
addToBuffer("'>UP</button></div>");
if(i==2)
addToBuffer("'>LEFT</button></div>");
if(i==3)
addToBuffer("'>RIGHT</button></div>");
if(i==4)
addToBuffer("'>DOWN</button></div>");
}
addToBuffer("</div>");
// JavaScript for buttons
addToBuffer("<script type='javascript'>");
for(i=1; i<5; i++) {
addToBuffer("$('#btn_on");
addToBuffer(clientId);
addToBuffer(i);
addToBuffer("').click(function(){var xmlHttp = new XMLHttpRequest();xmlHttp.open(\"GET\",'/");
addToBuffer(clientId);
addToBuffer("/");
addToBuffer(i);
addToBuffer("/',false);});");
addToBuffer("xmlHttp.send(null);");
}
addToBuffer("</script>");
The server has handler functions for urls / /1, /1/1/ /1/2/ /1/3/ /1/4/.
When I press any of the buttons, no request is being received in server.
How to solve this?

Related

While opening links in reverse order in new tabs, I want to exclude "sports" and "IR" links

I want to open links from contents from bottom to top in new tab:
driver.get("https://en.wikipedia.org/wiki/Sports_video_game");
WebElement contents = driver.findElement(By.xpath("//*[#id='toc']"));
List<WebElement> links = contents.findElements(By.tagName("a"));
String clickonlinkTab=Keys.chord(Keys.CONTROL, Keys.ENTER);
for(int i = links.size() - 1; i >= 0; i--)
{
links.get(i).sendKeys(clickonlinkTab);
links.findElement(By.partialLinkText("sports")).notclick();
links.findElement(By.partialLinkText("IR")).notclick();
}
I want Selenium to skip links which has "sports" and "IR" any where on it.
As "notclick" is not a valid method, the simplest solution is to check if the link text contains "Sports" or "IR" before performing the click action. E.g:
for (int i = links.size() - 1; i >= 0; i--) {
if (!(links.get(i).getText().toLowerCase().contains("sports")
|| links.get(i).getText().toLowerCase().contains("ir"))) {
links.get(i).sendKeys(clickonlinkTab);
}
}
Here is a link to a runnable test case where you can see the results, including printing to verify that it works. If you want to edit, making an account can be done for free via the edit button.

How to display dynamic checkboxes using dojo

I want to display dynamic checkboxes by iterating json array object. Can anyone guide me how can we do this?
After doing some internet surfing and playing around code I able write below code, which working fine for my scenario. So thought it will be helpful for others.
for ( var i = 0; i < roleJSON.length; i++) {
var role = roleJSON[i];
var tr = dojo.create("tr",{id:"rolebasecheckbox"+i,'class':'rolebasecheckbox'});
alert("tr=" + tr);
var td= dojo.create("td",{innerHTML:'<input id="roleBaseCb_'+i+'" value="'+role.role_id+'" dojoType="dijit.form.CheckBox" onclick="alert('onclick event')" type="checkbox" /> <label for="roleBaseCb_'+i+'">'+role.role_name+'</label>',align:'center'},tr);
alert("td=" + td);
if(i==0){
alert("i is 0");
dojo.place(tr, "roleBaseComboTR", "after");
}else{
dojo.place(tr, "rolebasecheckbox"+(i-1), "after");
}
}

How to create SwapView dynamically using Dojo

I am using Dojo v1.8 with Worklight; I would like create a SwapView dynamically in View, but I'm encountering problems...
HTML code:
<div data-dojo-type="dojox.mobile.View" id="listeInscriptionView"
data-dojo-props="selected:false,scrollDir:'vh'"
style="background-image: url('images/bg-texture.jpg');"
data-dojo-id="id">
</div>
JavaScript code:
var view = registry.byId(listeInscriptionView);
alert(view);
for(var i = 1; i < 3; i++ ){
var swap = new dojox.mobile.SwapView({
id: i,
selected:false
});
var head = new dojox.mobile.Heading({
label:'Swap' + i,
});
swap.addChield(head);
view.addChield(swap);
alert("test" + i);
}
The above does not work. How I can create the widget SwapView dynamically?
Is that a copy of your actual code? I have not actually tested it but there are syntax errors and typos:
registry.byId(listeInscriptionView);
should be
registry.byId("listeInscriptionView");
(missing quotes), and
swap.addChield(head);
view.addChield(swap);
should be
swap.addChild(head);
view.addChild(swap);
Maybe it works better with these errors fixed?

Adding atrribute to all elements with specifeid class using js

*JS*
document.getElementsByClassName('abc')[0].setAttribute('id', 'abe');
*html*
<div class="abc"></div>
<div class="abc"></div>
How to make this script work with more than one element?
Some thing like this
var divs = document.getElementsByClassName('abc');
for (i = 0; i < divs.length; i++) {
divs[i].setAttribute('id', 'abe');
}

Use of SPStatefulLongOperation

Can someone give me an example of the use of SPStatefulLongOperation? It's very poorly documented.
Here's an example of code I've just used. It applies a ThmxTheme (selectedTheme) to all SPWebs in an SPSite (site).
SPStatefulLongOperation.Begin(
"Applying theme to sites.",
"<span id='trailingSpan'></span>",
(op) =>
{
op.Run((opState) =>
{
for (int i = 0; i < site.AllWebs.Count; i++)
{
// Update status.
opState.Status = String.Format(
"<script type='text/javascript'>document.all.item('trailingSpan').innerText = '{0} ({1} of {2})';</script>",
site.AllWebs[i].Title,
i + 1,
site.AllWebs.Count);
// Set the theme.
selectedTheme.ApplyTo(site.AllWebs[i], true);
}
});
op.End(System.Web.HttpContext.Current.Request.UrlReferrer.ToString());
});
Note that the current value of opState.State is appended to the client's HTML (via HttpContext.Current.Response.Write and .Flush) every second. Thus you don't want to send any status message directly; you want to send some JavaScript that will update an existing status element on the page. (Here, the trailingSpan element.)