Jump to content

Need help with multiple $_GET Values


n33dl3

Recommended Posts

Hi there

What is the right way to handle more then one $_GET Value?

--

// Function handles the response from the PHP script.

function handleResponse() {

// If everything's okay:

    if(http.readyState == 4){

    // Assign the returned value to the document object.

        document.getElementById('outcome').value = http.responseText;

       

--

Now let's say I have two ID elements and the response text has two values, how can I send the first value to the first element id and the second to the second element id?

Do I need to add something like"document.getElementById('aer_version').value = http.responseText;" I need to split somehow the response text

Thanks a lot

Regards

RobH

 

Link to comment
Share on other sites

You could use xml or json and that would be much easier. However, you could simply use something to split the response, like a comma or whatever. Then you could split by the divider. I will give you an example.

 

In this example I am going to assume that you are using a | to divide the responses. So lets say the response from your php file is.

Joe Smith | Something about Joe Smith

 

and here is how you could split the response with js.

 

function handleResponse() {
    if (http.readyState == 4) {
        var response = http.responseText;
        //split the response by our separator
         var parts  = response.split("|");
        //write the first part of the split to your first div
        document.getElementById('div1').innerHTML = parts[0];
        //write the second part of the split to your second div
        document.getElementById('div2').innerHTML = parts[1]; 
    }
}

 

Now normally I would say to use xml or json but since you only have two responses coming back i would just do it that way.

 

Hope that helps,

Tom

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.