PHP语法中的JavaScript

I think this is a simple problem of my not knowing my syntax very well yet, but I am trying to get a js variable in a PHP, which actually happens to be in another js. I keep getting unterminated string literal error amoungst others general not working errors.

Code is as follows taking out the unnecessary

<script>
        jQuery(document).ready(function() { 
                var caNumber = document.getElementById("doc_id").value;                         
                var uploader = new plupload.Uploader({
                    url: '<?php echo admin_url('admin-ajax.php?project='.$_GET["project"].'&action='.$_GET["action"].'&number=caNumber') ?>'
                 });};
</script>

The problem in question is how to get the CaNumber in the url: where I have show CaNumber.

Thank you for time and assistance.

You are merging both php and javascript. Keep them separate.

url: "<?php echo admin_url('admin-ajax.php?project='.$_GET["project"].'&action='.$_GET["action"].'&number= ')?>"+caNumber;

You can't put a JavaScript variable into PHP code in that manner. Keep in mind that PHP is a server-side language whereas JavaScript is a client-side language. Meaning, they are executed on two different machines. - By the time JavaScript code is evaluated, the PHP code has long since completed it's job.

If you want to get values from JavaScript to PHP, you need to send them with a new request (AJAX, usually), or by using something like the more modern WebSockets feature.

However given that the PHP code is simply generating an URL, you might try adding a placeholder in the URL it returns, and then replacing it with your JavaScript value in the JS code.

Example:

<script>
    var cat = document.getElementById("catElem").value;
    var url = "<?php echo "/file.php?cat={{CAT}}"; ?>";
    url = url.replace("{{CAT}}", cat);

    console.log(url);
</script>

Keep caNumber out of your PHP statement, where it is unknown and has no meaning. Append it, with JS, to the string output by PHP:

jQuery(document).ready(function() { 
  var caNumber = document.getElementById("doc_id").value;
  var upUrl = "<?php echo admin_url('admin-ajax.php?project='.$_GET["project"].'&action='.$_GET["action"].'&number=') ?>" +
      caNumber;

  var uploader = new plupload.Uploader({
    url: upUrl
  });
};

As an additional note of equal importance, do NOT blindly dump PHP variables into a JavaScript string. Doesn't matter how trustworthy the source of that PHP variable is. In this case, you're using $_GET variables in it, which means you're opening the door wide for attacks - a malicious user can force the victim's browser to execute any JavaScript at all through the URL.

Instead, use...

url: <?php echo json_encode(admin_url(......)); ?> + caNumber;

This will handle all kinds of escaping and wrapping the string in quotes for you, thus closing the security hole.