Jump to content

Problem Passing AJAX Parameters to PHP


millercj

Recommended Posts

Running an Ajax script and the number of parameters i'm passing is dynamic. My parameter string is generated and sent to the PHP via the following function:

 

function save(numStd){

//Find Selected Class
var all = document.all ? document.all :
document.getElementsByTagName('*');
var elements = new Array();
for (var e = 0; e < all.length; e++)
if (all[e].className == 'active')
var currentClass=all[e].id; 

var sendParams=escape(numStd)+"&param1="+escape(currentClass);
var paramCounter=2

for(var i = 1; i <= numStd; i++){
window['lNameSave'+i] = document.getElementById("LastName"+i).value;
window['fNameSave'+i] = document.getElementById("FirstName"+i).value;
window['ageSave'+i] = document.getElementById("Age"+i).value;

sendParams =sendParams+"&param"+paramCounter+"='"+escape(window['lNameSave'+i])+"'";
paramCounter++;
sendParams =sendParams+"&param"+paramCounter+"='"+escape(window['fNameSave'+i])+"'";
paramCounter++;
sendParams=sendParams+"&param"+paramCounter+"="+escape(window['ageSave'+i]);
paramCounter++;

}
var urlNewStd = "/phpscripts/saveNewStd.php?param=";
http.open("GET", urlNewStd + sendParams, true);
document.getElementById("studentresult").innerHTML="<img src='/images/ajax-loader.gif' style='margin:50px 0 0 110px;'/>";
http.onreadystatechange = handleHttpResponseNewStd;
http.send(null);
}

 

 

if I input two records to send as parameters this is an example of what urlNewStd + sendParams looks like:

/phpscripts/saveNewStd.php?param=2&param1=4A&param2='Williams'&param3='Robin'&param4=55&param5='Moore'&param6='Demi'&param7=45

 

once it is in the PHP I can only access the first parameter which in the example would be "2"

 

I'm trying the get the Parameters in PHP via:

$variable= urldecode($_GET['param1']);

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/136440-problem-passing-ajax-parameters-to-php/
Share on other sites

What the interface is--is a window in which the user can add students to respective classes. The user creates as many "new student" fields (first name, last name, age) as they wish by clicking a button that number of times (so the number of parameters needed is dynamic). Then then the data in those fields needs to be passed via ajax to be inserted into a sql table.

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.