Joomla! is forcing my concat plus '+' to “

2019-08-07 15:00发布

I have this Multi-line string comprised of mostly html, so I decided to use single inverted commas as delimiters.

To keep it succinct, I have removed much of the html from the string to just focus on the error part.

jQuery("#myModal .modal-content").html('<div class="modal-header">' +
      '<h4 class="modal-title" id="myModalLabel">Duplicate Entry Found!</h4></div>' +
      '<a type="button" href="index.php?layout=studentprofile&id=' + studentid +'" target="_blank">View Student Profile</a>' );

What is happening is that the server is urlencoding the code and removing the plus signs + and adding %20in its place.

If I am writing the concatenation like ...studentprofile&id=' + studentid +" (ie. with spaces) the output is ...id='%20%20%20studentid%20%20%20'"

And If I remove all whitespaces from between the strings and the plus sign, like ...studentprofile&id='+studentid+" then the output becomes ...id='%20studentid%20'"

One interesting observation is this is only happening for single inverted commas, and If I just switch the commas it gets back to working correctly.

Other things which I'd like to add is this code used to work flawlessly on previous LAMP installations, but I have recently upgraded the whole stack so don't know if the the webserver or the php language, or even my framework which btw, is Joomla! is introducing this behavior.

One more discovery: This is only happening for the pluses around the studentid variable, rest of all the string with their pluses is working perfect.

OK, I seem to be onto something here, It clearly is Joomla!'s fault now, Found another similar question.

1条回答
等我变得足够好
2楼-- · 2019-08-07 16:03

Try the fllowing snippet. It does work:

var studentid = '2';

console.log(
'<div class="modal-header">' +
      '<h4 class="modal-title" id="myModalLabel">Duplicate Entry Found!</h4></div>' +
      '<a type="button" href="index.php?layout=studentprofile&id=' + studentid +'" target="_blank">View Student Profile</a>'
);

查看更多
登录 后发表回答