Jump to content

Passing a variable to php from ajax


pquery

Recommended Posts

Hi, I'll start off with saying that Ajax is not anywhere near my greatest language (and all the help pages I can find are mostly centered around ASP instead of PHP).

 

I have a drop down list which a user chooses a group (this is the passed variable) stored in the ajax called php page $group. (currently this is hard coded to a list I know that works so I can see the results come up in a page)

 

here is the ajax which I am using (I found this but it seems to be doing the job, also it looks like it can grab a variable but I'm not quite sure how to get it to pass through):

 

// Get base url

url = document.location.href;

xend = url.lastIndexOf("/") + 1;

var base_url = url.substring(0, xend);



var ajax_get_error = false;



//Get group name 





function ajax_do (url) {

// Does URL begin with http?

if (url.substring(0, 4) != 'http') {

	url = base_url + url;

}



// Create new JS element

var jsel = document.createElement('SCRIPT');

jsel.type = 'text/javascript';

jsel.src = url;



// Append JS element (therefore executing the 'AJAX' call)

document.body.appendChild (jsel);



return true;

}



function ajax_get (url, el) {

// Has element been passed as object or id-string?

if (typeof(el) == 'string') {

	el = document.getElementById(el);

}



// Valid el?

if (el == null) { return false; }



// Does URL begin with http?

if (url.substring(0, 4) != 'http') {

	url = base_url + url;

}



// Create getfile URL

getfile_url = base_url + 'getfile.php?url=' + escape(url) + '&el=' + escape(el.id);



// Do Ajax

ajax_do (getfile_url);



return true;

}

 

I need to get it to pass to this line in the corresponding file which is being called up:

 

//replace with dynamic group later 

$group = 'LEE';


 

I thought I might be able to do this with a get, but it's hard to tell since you can't see the url that the ajax is hiding.

 

Any tips for me Ajax gurus?

Link to comment
https://forums.phpfreaks.com/topic/109980-passing-a-variable-to-php-from-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.