• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 48
  • Last Modified:

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)
0
Ivan Golubar
Asked:
Ivan Golubar
1 Solution
 
Bill PrewCommented:
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
0
 
Ivan GolubarAuthor Commented:
actualproject2 = <?php echo $_SESSION["actualproject"]; ?> ;

Open in new window


But debugger sees it as:  actualproject2 = First project;

Check attached image.
string.png
0
 
Olaf DoschkeSoftware DeveloperCommented:
Yes, you need to put that into quotes:

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

Open in new window


Bye, Olaf.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now