Variable  problem: Unexpected identifier

Ivan Golubar
Ivan Golubar used Ask the Experts™
on
This is my code:
function show_btn(){
    var actualproject2 = new String('String');
    actualproject2 = <?php echo $_SESSION["actualproject"]; ?> ;
$.ajax({
  method:"POST",
  url: '/wp-content/themes/ne4/PJson.php',
  data:  {
    "getCanvas":1,
    "whichProject":actualproject2,
    },
    datatype: "text",
    success: function(strdate){
   console.log(strdate);
     }
 });
}

Open in new window


Uncaught SyntaxError: Unexpected identifier

In debugger I may see:
function show_btn(){
    var actualproject2 = new String('String');
    actualproject2 = First project;

Open in new window


I think the problem is blank space between "First" and "project", because it is also  underlined with red in debugger.
What correction must I perform to resolve this problem?
(i did try to solve it with:     var actualproject2 = new String('String');, but no success)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
If you are trying to assing "First project" to the string actualproject2 that you are creating, then:

function show_btn(){
    var actualproject2 = new String('First project');
}

Open in new window


»bp

Author

Commented:
actualproject2 = <?php echo $_SESSION["actualproject"]; ?> ;

Open in new window


But debugger sees it as:  actualproject2 = First project;

Check attached image.
string.png
Software Developer
Commented:
Yes, you need to put that into quotes:

actualproject2 = "<?php echo $_SESSION["actualproject"]; ?>";

Open in new window


Bye, Olaf.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial