Avatar of Ivan Golubar
Ivan Golubar
 asked on

Variable problem: Unexpected identifier

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)
JavaScript

Avatar of undefined
Last Comment
Olaf Doschke

8/22/2022 - Mon
Bill Prew

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
Ivan Golubar

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

Open in new window


But debugger sees it as:  actualproject2 = First project;

Check attached image.
string.png
ASKER CERTIFIED SOLUTION
Olaf Doschke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck