0

I'm using CakePHP 3.5 Url Helper to generate some Urls to be called using jQuery Ajax. I have the following Ajax:

$(".container").on("change", "#select_box", function(){
                url = '<?= $this->Url->build(["controller" => "tools", "action" => "getTools", "?" => ["param1" => "PARAM1_PLACEHOLDER", "param2" => "PARAM2_PLACEHOLDER"]]); ?>';

            url = url.replace("PARAM1_PLACEHOLDER", $(this).val()).replace("PARAM2_PLACEHOLDER", 5);

            $("#tools").load(url);
        });

And for some reason, my url is coming up like this

/tools/get-tools/param1=1&amp;param2=5 (with &amp; instead of &)

Because of that, when I use getQuery('param2') to get the value of query string parameter param2, I get null.

Any help please? Isn't this the way that I'm supposed to build url with query string parameters in CakePHP 3.5?

1 Answer 1

2

You can pass the second parameter to not escape the &:

$this->Url->build([
    "controller" => "tools",
    "action" => "getTools",
    "?" => [
        "param1" => "PARAM1_PLACEHOLDER",
        "param2" => "PARAM2_PLACEHOLDER"
    ]
], ['escape' => false]);
Sign up to request clarification or add additional context in comments.

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.