I hava a node.js app running on express with a dynamicViewHelper that hits an http service with http.request. Unfortunately, when I try to do this, because the http request is asynchronous and the function calling it is not, the page just renders before the http request is finished and I end up with undefined on my page.
I am basically looking for a way to put an asynchronous action (the http request), inside of a dynamic view helper which gets rendered out on the page. I know I can't just turn it into a synchronous function, so I am looking for another way to get that dynamic data to the view.
Also, is there a way to cache the data that is returned from an http.request()? I don't want to put it on the session, but I want any further requests made to the exact same URL to possibly be cached... Not as big of a deal as the first part of my question, though.
I figured it out. I'll just load it in my route so that res.render() isn't called until the request is done.
Related
I have inherited this code which runs a 1-second-JQuery-Ajax-loop on the client side. It used to heavily exploit cookies and I am trying to change it to plain stateless HTTP at least, but now I have the following problem:
Every POST from the client is processed, and the first few GETs too, but after a short while the server-side HttpHandler is not even called on GET requests and the client code success callbacks always get passed the same - non-updated - data.
//edit: since people tend to assume otherwise: I have stepped through the code with a debugger, so when I say "handler is not called on get requests" and "client code success callbacks get passed the same data always" I mean that quite literally.
I figure this might be a problem of the Web Server caching responses to HTTP requests, but it's kind of a wild guess.
So I have a bunch of questions which might help me solve such problems in the future:
Is this a reasonable theory?
I would like to somehow have an overview over all the HTTP requests
the server registers and how he chooses to process them.
Also, where and how would I go about configuring the server beyond
the web.config, if for example I wanted to configure its caching
behaviour?
It's the clientside cache which is causing this.
Set cache to false on your AJAX request.
$.ajax({
url: "http://your.url.here",
cache: false
})
.done(function(data) {
// ...
});
More details here.
I have a main JSP and process JSP. In process jsp I am committing the response and forward the response to a success page.
request.getRequestDispatcher("success.jsp").forward(request, response);
I am able to commit the response at the server side. Process jsp is also able to forward the response to success JSP.
But the url shows for example: http://process.jsp?param1=value1&parm2=value2
I want my output to display a clean as in url http://success.jsp
Please Note: This works perfectly fine for Java Servlet, i just tried it.
I am using only JSP instead of Java servelet, since this is our project requirement.
Can anyone suggest me a solution for this?
RequestDispatcher#forward() Is supposed to forward both the request and the response objects to another resource within the server. No response goes back to the client when you do a forward() and this is why the client shows the same initial URL.
For the client to show another URL you could use HttpServletResponse#sendRedirect(). This does go back to the client making it do a new request to the URL you want. So change it to:
response.sendRedirect("success.jsp").
Remember not to commit the response before doing this or you'll get an IllegalStateException
As to why you say that on a Servlet works, I'm not sure why, but is not how forward() is supposed to work, and JSP are compiled to Servlets so in the end they should behave the same.
I'm having a problem getting any response from urlfetch.Transport.RoundTrip in GAE Go. When I browse a page that makes the call in a browser, the call is executed as intended. When the same function is called from a POST request made by poclbm Bitcoin miner, I can't get a response.
The call is made by this package I made at line 77.
Is it possible, that in Google App Engine one can request data from other web pages under a HTTP GET, but not POST, or is there something else that can be causing this problem?
You can do POST request from App Engine using http.Client.Post, just make sure you create the http client with urlfetch.Client function.
I want to silently check for Session existence without Posting back page by using AJAX Timer and AsyncPostBack Trigger.
Now, I would like to know is there anyway to silently check whether ASP.NET C# if (Session["email"] = null) { Response.Redirect("Logout.aspx"); } something of this kind to check for every 10 seconds without Posting Back Page and without using AJAX by using something like jQuery or any other technology that is supported by .NET?
The server can push to a loaded page if you use an asynchronous controller with a partial view which is loading every set amount of time.
http://msdn.microsoft.com/en-us/library/ee728598.aspx
there is only one way to get to the server. send a request. that can be a "standard" request where the browser will refresh the screen when a response is sent. the other type of request is a ajax request. the difference is an ajax request contains a header to inform the server it's an ajax request. when the browser receives the response it will allow the developer to decide what to do with the response. either way a full request/response exchange takes place the only difference is how the browser handles the request.
jquery is a javascript library that includes functionality to make ajax request easier to setup.
to answer you question no, there is no way around making a request.
What happens from the point an HTTP request is received on a TCP/IP port up until the Page fires the On_Load event?
The below link should give you detailed explanation about the asp.net application life cycle process.
http://msdn.microsoft.com/en-us/library/ms178473.aspx
Brifely to say.
Request is received by the server, the server determines the ISAPI extension to handle the request based on filename extension.
In case this is first request, it will create an app domain for maintaining isolation with this and other applications running.
then it creates hosting environment which will also create the objects like HttpContext, HttpRequest and HttpResponse.
After this the HTTPApplication object is created .
Afterwards the events in the global.asax which is the class inherited from the HTTPApplication object fires in the order defined in the link above.
The browser recieves the http response
The browser parses http headers and starts reading the HTTP content.
Parsing first the <head> section and parsing this, putting external resources on the get queue (first, css then javascript, ideally)
Parsing the <body> content and drawing elements on the viewport.
When the DOM is drawed to screen and is completely rendered. the page fires the on_load event.
When the HTTP request reaches the server, the server will then prepare the necessary file that is requested by the client and send it to the client. The client will then receive the entire content of the HTML page. Note that this is just the HTML and the browser still needs to make additional requests to the server for images and other types of files like applets if necessary.
Finally, to answer your question, it'll have to depend on where you put the onload event. If it's for the then this will be invoked when the body has completed loading. If it's in other node items, as we call it in JavaScript, then it'll be on the complete loading of that particular item.
Hope it helps :)
Cheers!