HTTP.Request not returning expected data - f#-data

If I enter a value directly on the web form and click submit, it returns a record. When I run the code below, it does not return a record in the response body.
Http.Request("https://efiling.dir.ca.gov/PWCR/Search.action", body =
FormValues ["conCSLB", "22"])
What am I missing?

Related

how to get off result for the rest checkboxes

I used req.body to get answer of checkboxes using post method
The result was like this
{
1:"on",
2:"on",
4:"on"
}
But rest of them not even appeared or gave result as off

Persist data sent to a Pug template via render

I'm trying to find out how I can persist the data I pass to my Pug template from the Express render method.
I pass in some JSON data to the res.render() method in Express that renders my view with Pug. On the Pug template, I use that data immediately to populate one of my select elements with drop down values from the JSON data.
What I want to then do is store this data that was passed so I can use it in an event handler function I create for another field.
Basically, I'm passing a table name and the field names for the table, but for each table I have in the JSON data.
So the shape is like [{ tableName: "table name here", fieldNames: ['field1', 'field2', ...] }, ... ]
I have a select field for "choose a table name" and when the user picks a table name, I then want to get the fieldNames for a second select field that allows them to choose a field name to use. So I have an event handler setup on the "choose a table name" field that runs a little event handler I have setup in the pug template. Only problem is the event handler does not have access to the data that was passed to the Pug template originally.
I'm trying to google this but having no luck finding anything, so does anyone know how I can persist data sent via the res.render() method in a pug template for using after the page has been rendered inside an event handler or other functions?
Thank you!
Always be clear what is done at the server (pug) and what is done in client Javascript (browser).
While data passed to pug scripts are meant to be consumed at the server, it is possible to inject, for want of a better word, server data into client side Javascript variables.
The following creates two dropdown lists on the same page using the exact same data passed by Express. One is generated at the server, while the second is created entirely by Javascript running in the browser.
Express code:
app.get("/testdata", (req, res) => {
res.render("testdata", { data: [ 1, 2, 3, 4, 5]});
});
testdata.pug:
html
head
body
p Dropdown list generated at the server:
p
select
each n in data
option(value=n)=n
br
p Dropdown list generated in browser Javascript:
p
select#dropdown
script.
document.body.onload = () => {
const dropdown = document.getElementById("dropdown");
let data = JSON.parse(`!{JSON.stringify(data)}`); // line 18
data.forEach(d => {
const item = document.createElement("option");
item.innerText = d;
dropdown.appendChild(item);
})
}
I have used the same variable name in totally different contexts pointing to different entities. Be careful not to trip. For example, look at line 18:
let data = JSON.parse(`!{JSON.stringify(data)}`); // line 18
The first instance of data is a Javascript variable in the browser.
The second instance of data is a server object passed to the pug script in the render method. Basically any !{expression} instances found in a pug file are evaluated¹ when the view is rendered.
¹ I think the expression is evaluated and its toString method called. If I know it is an array, I could have used:
let data = [!{data}]; // line 18

Read parameter in ActionFilterAttribute that is not present in action's prototype

I am sending a form using Ajax, it has two inputs.
The receiving action only needs to consume one of the passed values.
An ActionFilterAttribute needs to consume the other argument.
For this reason, I wrote my action as
[AttributeImWriting]
public ContentResult Get(Guid value0) //[...]
but in my action filter when I try to do
context.ActionArguments["value1"]
I get an exception because the argument does not exist.
System.Collections.Generic.KeyNotFoundException: 'The given key 'value1' was not present in the dictionary.'
If I change the action's prototype to
public ContentResult Get(Guid value0, string value1) //[...]
Then I can read value1 from my filterAttribute.
So the question is: In an ActionFilterAttribute, how can I read an argument that was sent by a form, but which is not present in the prototype of the action on which the filter is applied?
I also tried using RouteData.Values but it didn't work any better.
If you are using POST to send values to controller side , in custom ActionFilterAttribute , you can get the parameters from Form property :
var value1 = context.HttpContext.Request.Form["value1"].ToString();
If you are using Get to send values to controller side , you can get the parameters from QueryString property ,then split and get each item:
var querystring = context.HttpContext.Request.QueryString;

Can Cloudant list/show functions return objects and arrays(any JSON)?

As per the API documentation for Cloudant: Show function can be used to render a document in a different format or extract only some information from a larger document. Same is the case for a list function, the only difference is that it applies on a set of documents. I created a design document with a show function as follows:
{ "shows": { "showDemo":"function(doc,req){return {'body': doc, 'headers':{'Content-Type':'application/json'}}}" } }
When I use this function, _design/showFunc/_show/showDemo/doc1, I get the following error:
{ "error": "unknown_error", "reason": "badarg", "ref": 1793182837 }
I have observed the same error when the show function returns an array. However, no error is given when HTML,Text, XML is returned. Can we say that list/show functions can only return data in a format other than JSON? This example shows the "Accept" header for req object request Object.
What's happening here is that the show function needs to return a response object. From the docs (see http://docs.couchdb.org/en/2.1.0/json-structure.html#response-object) the body field needs to be a string, so you can return whatever you like but it needs to be stringified or otherwise turned into a format that can be sent as HTTP.
If you want to send JSON then doing JSON.Stringify(doc) as the value for body should do what you expect.

NightwatchJS > Storing response from "elements" command and performing further actions

I have a button with the same class name that appears on the page in a few instances. How do I store the response from elements(i.e Web Element JSON Objects) in array to perform further actions on them as clicking and asserting? I've been trying to do the following but it did not work:
browser.elements('css selector', 'elem', function(res) {
arr = res.value;
console.log(arr);
a = arr[1].ELEMENT;
console.log(a);
browser.elementIdClick(a);
It prints the index of the ELEMENT, but the elementIdClick command does not perform any actions nor throws any errors in response. Please help
It should work:
this.elementIdClick(a) or this.api.elementIdClick(a)
if not could you print console.log(browser) and console.log(this)
It might be helpful.

Resources