Home » Php » php – JQuery .get() only passing first two data parameters in url

php – JQuery .get() only passing first two data parameters in url

Posted by: admin July 12, 2020 Leave a comment


I have a $.get() call to a PHP page that takes 4 GET parameters. For some reason, despite giving the $.get() call all 4, it only passes the first two. When I look at the dev console in chrome, it shows the URL that gets called, and it only passes action and dbname. Heres the code:

$.get('util/util.php', { action: 'start', dbname: db, url: starturl, crawldepth: depth }, function(data) {
        if (data == 'true') {
            status = 1;
            $('#0').append(starturl + "<ul></ul>");
            while(status == 1) {

        } else {
            show_error("Form data incomplete!");

and heres the URL that I see in the developer console:


** EDIT **
I have been informed that I need to encode the URL that I am trying to pass through the header. How would I go about encoding it in javascript, and decoding it in php?

How to&Answers:

Are you sure that the starturl and depth variables are defined? A simple alert() before the $.get() will be enough to check.

In regards to your edit, you can encode strings in JavaScript with the encodeURIComponent function. And decode it back again in the PHP with urldecode. They both take one string argument.


Probably you will need to check whether your input strings are properly quoted. Internally jQuery will build the paramter string out of the parameter map you specified using its param() method. This method will construct an object of the keys and values, which will likely not be parseable if you quoted your keys and values incorrectly.

@ Felix Kling: jQuery automatically encodes keys and values of the parameter string with encodeURIComponent.