2012-03-06 83 views
0

由於某種原因它不是processing-- VAR用戶=變量,當我觀看results-- mysite.com/image_upload/uploads/';/Java腳本不處理PHP變量

(function($){ 
    $.simpleuploader = {version: '0.1'}; 
    $.fn.simpleuploader = function(options){ 
    // the container to inject the form into 
    var $this = $(this); 


    var user = '<?php echo json_encode($uid); ?>'; 

    // set defults 
    var defaults = { 
     prefix: 'simpleuploader-', 
     latency: 500, 
     reuse: true, 
     when: 'onchange', 
     submitText: 'Submit', 
     disabledOpacity: .3, 
     settings: { 
      fullPath: 'http://www.mysite.com/image_upload/uploads/' + user + '/', 
      relPath: '../uploads/' + user + '/', 
      maxSize: '4194304', 
      maxW: 300, 
      maxH: 300, 
      colorR: 255, 
      colorG: 255, 
      colorB: 255 
     }, 
+0

究竟是什麼以JavaScript的形式發送到瀏覽器? – David 2012-03-06 21:56:01

+0

嘗試將雙引號引入php回顯。 – kirilloid 2012-03-06 21:56:41

+0

請寄出'<?php var_dump($ uid); ?> – bfavaretto 2012-03-06 21:56:47

回答

0

json_encode()產生javascript對象,並且不屬於引號內。您的echo聲明中可能存在引用或者其他內容,這些內容會混淆javascript。嘗試將該行更改爲此。

var user = <?php echo json_encode($uid); ?>; 

話雖這麼說,json_encode()在單一變量是不好的做法,而奇怪的是做一些事情。如果$ uid只是一個數字,爲​​什麼不使用:

var user = <?php echo $uid; ?>;