Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Url嵌入两次_Javascript_Php_Jquery_Json_Codeigniter - Fatal编程技术网

Javascript Url嵌入两次

Javascript Url嵌入两次,javascript,php,jquery,json,codeigniter,Javascript,Php,Jquery,Json,Codeigniter,我有以下脚本: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $( document ).ready(function() { $(function() { $('#upload_file').submit(function(e) { e.preventDefault(); $.ajaxFileUpload({

我有以下脚本:

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$( document ).ready(function() {
$(function() {
   $('#upload_file').submit(function(e) {
      e.preventDefault();
      $.ajaxFileUpload({
         url         :'./upload/upload_file/', 
         secureuri      :false,
         fileElementId  :'userfile',
         dataType    : 'json',
         data        : {
            'title'           : $('#title').val()
         },
         success  : function (data, status)
         {
            if(data.status != 'error')
            {
               $('#files').html('<p>Reloading files...</p>');
               refresh_files();
               $('#title').val('');
            }
            alert(data.msg);
         }
      });
      return false;
   });
});
  setInterval(function refresh_files()
{
   $.get('./upload/files/')
   .success(function (data){
      $('#files').html(data);
   });
},5000
);

$('.delete_file_link').live('click', function(e) {
   e.preventDefault();
   if (confirm('Are you sure you want to delete this file?'))
   {
      var link = $(this);
      $.ajax({
         url         : '<?php echo base_url()?>/upload/delete_file/' + link.data('file_id'),
         dataType : 'json',
         success     : function (data)
         {
            files = $('#files');
            if (data.status === "success")
            {
               link.parents('li').fadeOut('fast', function() {
                  $(this).remove();
                  if (files.find('li').length == 0)
                  {
                     files.html('<p>No Files Uploaded</p>');
                  }
               });
            }
            else
            {
               alert(data.msg);
            }
         }
      });
   }
});
});
以及以下观点:

<!doctype html>
<html>
<head>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
   <script src="<?php echo base_url()?>js/site.js"></script>
   <script src="<?php echo base_url()?>js/ajaxfileupload.js"></script>
   <link href="<?php echo base_url()?>css/upload.css" rel="stylesheet" />
</head>
<body>
   <h1>Upload File</h1>
   <form method="post" action="" id="upload_file">

       <?php //foreach($Patients_Name as $scan_types){?>
      <label for="title">Patient Name:</label>
      <input type="text" name="title" id="title" readonly value="<?php echo $Patients_Name?>" />


      <label for="userfile">File</label>
      <input type="file" name="userfile" id="userfile" size="20" />

      <label> Comment/Description:</label>
      <textarea rows="4" cols="20" id="comments" name="comments" placeholder="Please provide a brief description">  </textarea>


        <td> <p>
        <label for="scan_type">Scan Type <span class="required">*</span></label>
        <?php echo form_error('scan_type'); ?>




        <select  data-placeholder="Select a Scan Type..." class="scan_type"  name="scan_type" id="scan_type" >
                <option ></option>                          
                                     <?php foreach($dropdown_type as $scan_types){?>
                              <option  value="<?php echo $scan_types['dropdown_type']?>" id="<?php echo $scan_types['dropdown_type'] ?>" ><?php echo $scan_types['dropdown_type']?></option>
                              <?php } ?></select>

</p>
                </td>
      <input type="submit" name="submit" id="submit" />
   </form>
   <h2>Files</h2>
   <div id="files"></div>
</body>
</html


我认为您的问题是由
$.ajaxFileUpload
配置中的相对url引起的。 为
$.ajaxFileUpload
提供
url
键时,请尝试在javascript代码中使用绝对url

您可以使用php中的基本url创建一个javascript变量,在您的视图中使用如下内容:

// in <head> or somewhere near the top before any other <script> tag
<script>
    var BASE_URL = '<?php print base_url(); ?>';
</script>
// in <head> or somewhere near the top before any other <script> tag
<script>
    var BASE_URL = '<?php print base_url(); ?>';
</script>
// ...
  $.ajaxFileUpload({
     url: window.BASE_URL+'/upload/upload_file/', 
// ....