php - ajax authentication in a div -


O all .. a question from JJ in Holland ..

I'm busy in my first AJAX Web programming and really is like the idea where a PHP file (index) is loaded and able to load and refresh the contents of the div without refreshing the XMLhttprequest page.

Things are going well so 4 div sections receive different content, depending on which menu you press (via all the gatedata functions and XML).

My last step is to integrate an additional orthation device. I try to apply a good jquery fade in the system with a login.php with the input field for the username and pass I am; A process_login.php that compares data with mysql and if someone matches or does not match; And finally a secure page where users can logout if they are successfully authorized. When I use login.php directly in the browser

When I use it to load it in a div section at login.dphp on login.php, then this page will work without thinking It looks like I index.html does not work. Because it seems that it can no longer use the function which is declared on login.php page .

Reading Ajax for the dummy does not let me answer anyway though I am convinced that the logical explanation for this fact should be easy to understand.

I can not find my head around it ... any information is welcome ... welcome

j j

< Div class = "post-text" itemprop = "text">

The Javascript loaded through AJAX is not part of the window. You have to explicitly execute it (such as using eval ), there is no direct solution to this problem, so you can learn about those resources through resources loaded through Ajax. The need to come up with the model of your application is

The best way to do this is to create some application-wide conference - e.g. Set up a cross reference of pages & amp; Script files, and $ GetScript to load them on demand. Ideally you will see whether a resource is already full before reloading it or not.

Here's a simple idea that you can use to add tags to your login.php , e.g.

& lt; Span id = "script" style = "display: none" & gt; Login, / script / login.js & lt; / Span & gt;

Then, after an AJAX call that loads a page, do something like this:

  data = $ ('# wrapper'). ('#scripts') Html () Split (','); If (window! [Data [0]]) {$ .getScript (data [1]); }   

So basically you are passing some information in HTML that the loader uses it to use the first parameter is a namespace, so you can check that it preloaded are done. The path of the second script is.

You can create an account for more than one script, use JSON for data format. But this is a basic idea.

Yes, you can always include all of your scripts in the front, too :) However, loading on demand is a good idea for any non-responsive application, so you have to make things happen to you Do not clutter with scripts do not need to. The log in script is going to be required only once per session.

Comments