0

I use the function "load" of Jquery for load page , in this url i send by "load" some values as this example :

jQuery("#load_data").show(1000).load("index.php?send_values="+datasend+"");

The value "datasend" get these values from function javascript as this :

    function getvalues()
    {
    var getdata="value 1";
    getdata +="value 2";
    getdata +="value 3";

var datasend=getdata;
    }

If insert alert inside funtion i get all values , for example :

        function getvalues()
        {
        var getdata="value 1";
        getdata +="value 2";
        getdata +="value 3";

    var datasend=getdata;

alert("Show"+datasend);
        }

But if i use load of Jquery , this no works :

       function getvalues()
        {
        var getdata="value 1";
        getdata +="value 2";
        getdata +="value 3";

    var datasend=getdata;

jQuery("#loader").load("index.php?send_values="+datasend);
        }

The other side in the page i want send/get values i have code in PHP , but when i do :

<?php echo $_REQUEST['send_values'];?>

Only get the first data in this case "value 1" and no all values , but with javascript "alert" i get all values but load of jquery no send all values by URL for finally get all values

Thank´s for the help , regards

2
  • Are you sure you get "value 1"? Commented Jan 14, 2015 at 19:17
  • 1
    Um, the string would be "value 1value 2value 3" and you really should be encoding the querystring. What do you expect to be sent exactly. Commented Jan 14, 2015 at 19:18

2 Answers 2

1

If you check again, you will see that the data that arrives at the server isn't "value 1", but only "value".

A correct URL can't contain spaces, so the load method uses space as a separator between the URL and an optional selector to get a fragment from the loaded data. As there are spaces in the value in datasend, only the part up to the first space is included in the URL, the rest is interpreted as a selector.

You would use the encodeURIComponent method to encode the value so that it can be used in the URL:

jQuery("#loader").load("index.php?send_values=" + encodeURIComponent(datasend));

Alternatively you can use the data parameter of the load method to include the data:

jQuery("#loader").load("index.php", { send_values: datasend });
Sign up to request clarification or add additional context in comments.

Comments

0

Try doing:

var datasend=encodeURIComponent(getdata);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.