Hey guys, nice to meet you.

I have PHP/MySQL driven site. I have finally found an AJAX script to load my data in a div on the same page. It works if i click a static link, but the main purpose i need is to click link with dynamic album ids in the url, which doesn't work. I cannot tell if it is simple syntax issue in the link or whether i cant use the AJAX script for this type of thing. I have no experience with AJAX. And i'm only a moderate user of the others.

This is the AJAX script:

<script type="text/javascript">

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}

</script>

which is between the header tags

And this is the PHP that works fine (it loads the page but obviously with errors cause it cannot find what album to get):

<a class="pics" href="javascript:ajaxpage('jobs/list-jobs-detail.php', 'mainwindow');">

And when i need to add the album id it doesnt work, despite displaying the URL correctly when i hover over the link (it just wont load the content at all):

<a class="pics" href="javascript:ajaxpage('jobs/list-jobs-detail.php&album=<?php echo $row['al_id']; ?>', 'mainwindow');">

Really appreciate any help you can give me.

NB: This is the MySQL query in case you needed it:

$sql  = "SELECT jobboard.*, joboffers.*
				FROM jobboard JOIN joboffers
				ON jobboard.job_num = joboffers.jobnum
	         WHERE joboffers.al_uname = '$session->username'
			 	ORDER BY joboffers.offerdate Desc";		 
$result = mysql_query($sql) or die('Error, get user info failed. ' . mysql_error());

while ($row = mysql_fetch_assoc($result)) { etc etc...

>> check $row getting value or not. If it is same field id in both tables then you have to get it by alias name.
and try to echo $row;

>> try with a static query string :

<a class="pics" href="javascript<b></b>:ajaxpage('jobs/list-jobs-detail.php&album=2', 'mainwindow');">

>> and when you use GET method in ajax send, then i think we cannot get url query strings in jobs/list-jobs-detail.php page.
so, you have to change GET to POST.
or put one hidden variable for album id and use GET.

Do you have this page online for us to see ?

Unfortunately not. Ill try upload something now, however i would need to strip everything back to be public. And there will be many faults. So just focus on the left and middle panels/divs.

OK i've got something up there now that is working. In the middle [vertical] div there is a list of jobs.

The first link (*** Doesnt Work ***) has a variable hardcoded in

The second link (*** Works ***) has no variable at all (forget about the error messages on loading)

And finally, the images in the list below that, have the link injected with php (displaying correctly: jobs/list-profile-detail.php&album=234)

Now making those first 2 control links showed me that the problem isnt in my php, but more broadly when a variable is added to the url (&album=XX).

So I think the problem is the AJAX script itself wasnt designed for this.

Can anyone show me the code changes I need to make? Or correct me if my assumption is wrong.

http://www.horizoneslchina.com/horizonv7/

>> check $row getting value or not. If it is same field id in both tables then you have to get it by alias name.
and try to echo $row;

>> try with a static query string :

<a class="pics" href="javascript<b></b>:ajaxpage('jobs/list-jobs-detail.php&album=2', 'mainwindow');">

>> and when you use GET method in ajax send, then i think we cannot get url query strings in jobs/list-jobs-detail.php page.
so, you have to change GET to POST.
or put one hidden variable for album id and use GET.

Sorry im not quite sure what you mean, could you explain more with examples?

btw, the variable is not passing through to the new page.

what your jobs/list-jobs-detail.php contains???


>> and when you use GET method in ajax send, then i think we cannot get url query strings in jobs/list-jobs-detail.php page.
so, you have to change GET to POST.
or put one hidden variable for album id and use GET.

Sorry for my confusing post..

for this you have written your correctly..

and follow prieateas tip...

You have &album= , it should be ?album=

BRILLIANT!!! Thank you. Why is it coding always takes 5hrs of research to find out you had 1 character wrong :P

The div will show the extended details of those entries. I will use this for multiple things throughout the site.

OK so the page is coming along quite well, but im hitting a hurdle now.

I cannot get variables sent to the divs unless i reload the whole page, in which case all the divs revert to the original content.

If you look at the page now, you will see the jobs listed in the middle div, when you click on one it loads to the right (contentcolumn). In this contentcolumn, I have forms which i would like to process, remaining in the same div, without changing everything else. I can get the form to load the correct page, but the variable (neither GET or POST) are passing through.

Can anyone give me some advice on how this could be achieved? I can only get them passed if i hard code them into the URL. The GET form doesnt send them.

<form action="javascript:ajaxpage('mysql/update_status.php', 'contentcolumn');" method="get">
					<tr><td>	
						 <input type="hidden" name="id" value="<?php echo $row2['al_id']; ?>" /></input>
						 <input type="hidden" name="firstname" value="<?php echo $row2['firstname']; ?>" /></input>
						 <select name="listStatus">
												<option value="Send Offers">SO</option>
												<option value="Awaiting Docs">AD</option>
												<option value="Active">W4</option>
												<option value="Interviewing">IN</option>
												<option value="Almost Signed">AS</option>
												<option value="Awaiting JOR">AJ</option>
												<option value="Not Talking">NT</option>
												<option value="Visa Pending">VP</option>
												<option value="In Transit">IT</option>
												<option value="Arrived">AR</option>
												<option value="Teaching">TE</option>
												<option value="Fee Received">FR</option>
												<option>--</option>
												<option value="Not Available">NA</option>
												</select>
							
						 <input type="submit" name="modify" value="Update" class="bt_login" /></input>
				</td></tr>
				</form>

And this is what I have at the top of the next page:

// Form Values
	$id   = $_GET['id'];
	$firstname = $_GET['firstname'];
	$status = $_GET['listStatus'];
	
	echo $id;
	echo $firstname;
	echo $status;

But they are blank

Next time, please post a new problem in a new thread. Since this was already marked as solved, changes are slim to get new input.

Next time, please post a new problem in a new thread. Since this was already marked as solved, changes are slim to get new input.

OK sorry, jsut thought cause it was related.

You can always post a link to this one of course. Just wanted to help you get a better response...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.