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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.