use session and still be ajax? - ajax

i am using ajax and jsp, but instead of using out.write() in jsp side, i do write the response string into session o object, then i open a colorbox panel and write the session value into page.
is doing this make my site not-ajax?
i understand that using querystring is an other way around, what is the difference between my solution and querystring solution?
thnx

No. AJAX is just a process for letting the client talk to the server without reloading the page. A lot of people think it is all of the dynamic behavior on the page as well, but that's been there before AJAX was first made possible in 2005 when Microsoft added the XMLHttpRequest object to IE.

Related

Maintain Session between ASP Pages called by Ajax

I've an odd problem.
I've a classic ASP application, which is working very well.
On another classic ASP application, I try to make Ajax requests to the first one, but the session variables are not maintained.
I tried two things :
- if I call page1.asp which makes a Response.Redirect to page2.asp, session object is empty on page2.
- if I call page1.asp and in case of success call page2.asp, same result.
Of course, this is working well if not called by Ajax, so page1 and page2 are OK.
$.ajax() or native XHR, same results.
Do you have any idea ?
Thank you,
EDIT : using Server.Transfer and setting all parameters in page1 did the trick, but did not explain to me why :(

Is it right to check session using ajax and redirect page?

I am planning to validate session for secure content using ajax. This will prevent access to secure page after logout or using browser cache.
Is this right approach to implement java script in html body tag to validate the session for every page load?
I tried with $( document ).ready(). But the browser cache retains the old value which says session alive.
Any suggestion on this?
The usual approach is to assign the session value to a method inside your controller. Then when you require the session value, call the method.

What is this the meaning of "Reload safe" web pages and can it be achieved with Ajax?

1) I saw an interview question on this, and I'm assuming it's something to do with form submission and avoiding double submissions. Can someone confirm this?
2) Assuming this assumption is correct, can this be done with Ajax? If so is there a link someone can point me to?
(I'm assuming you'd generate some sort of random number and include it in the form as a hidden field, then ensure that number hadn't been submitted before for the session).
Redirect-after-post is a technique to avoid problems with the user refreshing or using the back button to get back to a posted form. In short, instead of providing a response page to an HTTP post, which will trigger another post if its reloaded, you issue a 303 redirect (or a 302, to support ancient browsers by taking advantage of a bug that is as old as the web). This causes the browser to issue a second HTTP request - a get this time - and if the response page to that is reloaded there shouldn't be any problems. Just make sure that all the changes are made by the post handler and the page you redirect to has no side effects.
If you post using XMLHttpRequest then the redirect will be followed; unless you specifically support it using the hash part of the location or the new HTML5 history methods then the back button and reload aren't going to trigger an AJAX post again.

is it possible to do partial postback on web?

I read some paragraphs in a book saying that it is not possible to do a partial postback for web, even AJAX is employed. Ajax will postback everything and update only ajaxfied controls.
However, on pages I made using ajax, I used Fiddler to monitor the transportation. I found when the page initial load, it loaded everything include pictures .... However, when I click a button and do a ajax postback. I can only see the some data were loaded.... Looks like it doesn't need to reload the whole page again.
I don't know if what I see is correct? Or the book I read is correct?
Thank you guys.
That depends what you put in the term "postback".
The AJAX call will send the complete form data back to the server, just as if the form was posted normally. The server will answer with a partial response that only contains the parts of the page that should be updated.
So, the request is not partial, but the response is.
I am not sure how you are posting back from the client side. I am guessing you are using UpdatePanels. How well you 'AJAX-ify' a web page depends on what method you employ.
UpdatePanels - Read Dave Ward's posting on them - http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/
PageMethods to post back to a web service, get the data and update the DOM to display the result
JQuery and other such AJAX frameworks to post back to a web service
I am sure the link above should clear things up a bit
I'm having a hard time understanding your terminology. I'm not really sure what a "postback" is, much less a "partial" one. I do know that one of the basic ways to transmit information to an HTTP server is via a POST request, which is usually used when submitting forms. If you mean to say that the entire form is transmitted when you click a submit button, I believe you'd be right.
You also seem to be doing something with AJAX, but it's difficult to tell. The whole point of AJAX is to have dynamic data displayed on a page without resorting to reloading it. Defining what to send and what to do with the results is entirely up to your own JavaScript. So unless you're using a framework, which you don't specify, there is no such thing as "ajaxified controls."
In any case, "AJAX" usually means using the XMLHttpRequest() method of modern browsers to send data to servers without refreshing the page. When you call this function, you specify exactly what data to send. This has nothing to do with HTML forms. One caveat: if you are indeed using a library for AJAX, it might impose additional limits on how you structure information to send.

Is there any better approach then using Ajax Update panel in SharePoint WebParts?

We are using Ajax Update Panel in SharePoint web part to avoid postback, Certainly it is the easiest approach out there to provide AJAX functionality.But at times it feels like the performance is horrible!
Are there any better approach where in you get better performance then AJAX update panel.
If you're interested in better performance then the Update Panel isn't going to help you.
It's purely a User Experience thing!
When you're using the Update Panel:
Browser is still doing the full post
to the server
Server is doing all the usual work
for ALL the web parts on the page
Server graps the HTML inside the
update panel and sends this and
ViewState to browser
Browser replaces ViewState and HTML
inside Update Panel
But Using the Update Panel is very easy and you don't have to know any JavaScript
Using "real" AJAX would mean:
You have to know JavaScript
You have to know/develop Web Services
BUT only the requested functionallity will have to run on the server, so you'll usually get a lot better performance
NEVER EVER EVER user MS Ajax and the update panel. You will be burnt sooner or later.
Instead, use jQuery, and it's AJAX methods.
Why?
A) jQuery is smaller (and therefore faster?)
B) You can do more with jQuery by iteself than ms AJAX
C) Trying to hide AJAX in server controls is a dumb idea from the start
d) Web forms and server controls in general suck - less is more
e) Sooner or later you will need to get down and dirty with AJAX - better to start at a lower level
I suggest instead of using Asp.NET Update Panel. You can create an .ashx file handler that will expose your server side functions. Then with this you can use jQuery and Ajax to call your server side functions. This will be faster and cross browser issues will be kept to a minimum.

Resources