Search code examples
jquerywordpressloadampersand

How to put & in in URL with jQuery.load?


I have a Wordpress page that should load some code from the server using jQuerys load method:

<div id="mydiv"></div>
<script>
jQuery("#mydiv").load("http://localhost/testserver/wp-content/plugins/myplugin/scripts/view/test.php?x=1&amp;y=2&amp;z=3");
</script>

My test.php script is:

<?php error_log(var_export($_GET,true)); ?>

But I am unable to get the parameters x, y, z correctly in the test.php script: The output in the error log shows:

'x' => '1',
'amp;y' => '2',
'amp;z' => '3',

(If I use x=1&y=2&z=3 in the url string, I just get 'x' => '1', in the error log).

Am I doing something wrong or could this be a Wordpress or jQuery bug?


Solution

  • http://api.jquery.com/load/

    Example: pass arrays of data to the server.

    $( "#objectID" ).load( "test.php", { "choices[]": [ "Jon", "Susan" ] } );