473,703 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New to Ajax - Returning Javascript and $_SESSION information. (Using PHP)

6 New Member
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website.

Here is my problem:

The user uploads the file.
The server processes the file and stores a $_SESSION['code'] variable.
After the upload is complete, the server supplies a link that allows the user to view their link codes.
Once they click the link, the page will return the information stored in the $_SESSION['code'] variable. The normal link which opens a new page works flawless. However, when I try to return that information using AJAX, the $_SESSION['code'] variable is showing up as empty.

Here are the files I'm using:
upload.php
This page will process the upload, rename the file, move it, store some database information, and set the session variable $_SESSION['code']
This page contains a script tag with ajax.js as the src.
When the upload is complete, it will display a link that allows the user to execute the getLinkCodes function
getLinkCodes('l inkcodes.php', 'maincontainer' );

ajax.js
Expand|Select|Wrap|Line Numbers
  1. function getLinkCodes(datasource, divID){
  2.     var XMLHttpRequestObject = false;
  3.  
  4.     if (window.XMLHttpRequest) {
  5.         XMLHttpRequestObject = new XMLHttpRequest();
  6.     } else if (window.ActiveXObject){
  7.         XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  8.     }
  9.  
  10.     if (XMLHttpRequestObject) {
  11.             var obj = document.getElementById(divID);
  12.             obj.innerHTML = "Loading...";
  13.             XMLHttpRequestObject.open("GET", datasource);
  14.  
  15.             XMLHttpRequestObject.onreadystatechange = function(){
  16.                 if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
  17.                     obj.innerHTML = XMLHttpRequestObject.responseText;
  18.                 }
  19.             }
  20.             XMLHttpRequestObject.send(null);
  21.     }
  22. }
linkcodes.php - This will actually display the link codes so that the user can copy and paste them into a forum without any further editing.
This is the page that the XMLHttpRequest actually returns.
[code]

<script type="text/javascript" src="templates/base.js"></script>
<script src="templates/members/multifile_compr essed_image.js" ></script>
<script type="text/javascript" charset="utf-8">
<!--
var img_files = {};
try
{
img_files = [<?php echo $_SESSION['code']; ?>];
}
catch ( error ) { img_files = {}; }


function write_tags ( type, where )
{
if ( typeof where == 'undefined' ) return false;
var target = $(where);
if ( !target ) return false;

var code = '';
var cntr = 1;

var str = new Array();

for ( var i = 0; i < img_files.lengt h; ++i )
{
var file = img_files[i];

switch ( type )
{
case 'link_bb':
{
if ( file.is_image == 1 ){
code += '[img]' + file.thumb_url + '[/img] ';
if ((cntr%4) == 0){
str.push(code);
code = '';
}
cntr++;
}else{
code += '' + file.name + '';
str.push(code);
code = '';
}
} break;

case 'link_html':
{
if ( file.is_image )
var code = '<a href="' + file.url + '">\n <img src="' + file.thumb_url + '" alt="' + file.name + '" />\n</a>\n';
else
var code = '<a href="' + file.url + '">' + file.name + '</a>\n';
str.push(code);
}
break;

case 'direct_bb':
{
var code = file.is_image ? '[img]' + file.d_url + '[/img]' : '' + file.name + '';
str.push(code);
}
break;

case 'direct_html':
{
var code = file.is_image ? '<img src="' + file.d_url + '" alt="' + file.name + '" />' : '<a href="' + file.d_url + '">' + file.name + '</a>';
str.push(code);
}
break;

case 'direct_url':
{
str.push ( file.d_url );
}
break;
}
}
if (code != '' && type == 'link_bb'){
str.push(code);
}
target.value = str.join("\r\n" );
}

function switch_bb_case ( bb_case )
{
var target = $('link_codes') ;

function toUpper(str){al ert(str);}

if ( bb_case == 'upper' )
{
target.value = target.value.re place ( /\[(\/)?img\]/gm, '[$1IMG]' );
target.value = target.value.re place ( /\[(\/)?url\]/gm, '[$1URL]' );
target.value = target.value.re place ( /\[url=/gm, '[URL=' );
}
else
{
target.value = target.value.re place ( /\[(\/)?IMG\]/gm, '[$1img]' );
target.value = target.value.re place ( /\[(\/)?URL\]/gm, '[$1url]' );
target.value = target.value.re place ( /\[url=/gm, '[url=' );
}
}

function imgInit ( )
{
write_tags('lin k_bb','link_cod es');
}
addLoadEvent ( imgInit );
-->
</script>

<div class="middle1" >
<div align="center">
Linking codes: <span class="link" onclick="write_ tags('link_bb', 'link_codes');r eturn false;">BB format</span> - <span class="link" onclick="write_ tags('link_html ','link_codes') ;return false;">HTML format</span>
&nbsp; &nbsp; &nbsp;Direct link: <span class="link" onclick="write_ tags('direct_bb ','link_codes') ;return false;">BB format</span> -
<span class="link" onclick="write_ tags('direct_ht ml','link_codes ');return false;">HTML format</span> -
<span class="link" onclick="write_ tags('direct_ur l','link_codes' );return false;">Just the direct URLs</span>
</p>
<textarea rows="15" cols="100" id="link_codes " name="link_code s" style="padding: 2px;"></textarea>
</div>
</div>
[/code]

As I said, the linkcodes.php is the "lext" that the getLinkCodes function returns. However, The javascript in the linkcodes.php page does not load at all because I'm guessing it's not passed back as text.

Please let me know what you guys think and thanks for the help in advanse.

Steven
Jul 8 '07 #1
1 2890
bsprogs
6 New Member
I just realized there are a few spelling errors. I was typing too quick to get this message posted so please ignore them :)
Jul 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2929
by: Manish | last post by:
I am developing a photo gallery. 1. The user will be able to upload the photo a) Edit the photo using various GD library functions viz. flip, rotate, ... 2. AJAX is implemented in a small part -------------------------------------------------------------------------------------------------------------------------------- ajax.php
15
5950
by: Evil Otto | last post by:
My page loads, and calls an init() function that returns content to a div on the page, as well as setting a $_SESSION variable. The content it returns includes a link that calls the same variable, but I get an error that says the index isn't defined. The second two calls are AJAX-generated. The second call immediately echos the $_SESSION variable back after it sets it, and it sets it properly. But the subsequent request doesn't see...
1
4031
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
13
3999
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks, asynchronously. These tasks might take long time so I want to keep the user informed of the progress. The problem is that only the PHP script knows the progress, how can the web page gets these information from PHP script?
5
3686
by: Mike | last post by:
Hello, I have a Login page that checks a Db for a Un and Pw using ajax. If the Login is incorrect, they just get a embedded message. If it is correct, I want to redirect COMPLETLY. Whats happening is the new page is being embedded into the login page, and I dont want that. ............................. if ($rowcount==0){ echo "<p>Wrong Username or Password Dufus</p>"; }
3
2609
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to solve the problem. Here is the previous post http://bytes.com/forum/thread798289.html Trying to trace the problem I have written a code (Separate from The Form Validation) which sends 300 requests with an interval of 10 miliseconds and displays the...
5
2394
by: sbettadpur | last post by:
Hello everybody I have some issues in my program. Let me explain my requirement briefly, i am using php, mysql, javascript and ajax for my application. when my application opens means if user logs into application automatically a pop up window should come, means i don't want for every time that should open, For specific condition only pop up window will open. Let me explain that condition i have table called interview and field...
1
4606
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
5
4464
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php script works perfectly and gives me an entire table of correct data. The problem is that when I click...
0
8667
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7861
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4429
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3122
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2063
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.