2013-04-22 62 views
0

我在包含购物车脚本的页面上发生错误。Ajax错误:编辑jcart.js中的路径以修复

Error: 'Ajax error: Edit the path in jcart.js to fix.'

据我所知,问题是围绕文件的相对路径。我尝试了各种各样的变化,以获得正确的路径无济于事。

该错误是特定于名为jcart.js的JavaScript文件中的文件路径位置变量。该文件的位置如下:

文件/目录:

  1. domain.com/folder/jcart/js/jcart.js
  2. domain.com/folder/jcart/config-loader .PHP
  3. domain.com/folder/jcart/relay.php

代码:

var JCART = (function() { 

// This script sends Ajax requests to config-loader.php and relay.php using the path below 
// We assume these files are in the 'jcart' directory, one level above this script 
// Edit as needed if using a different directory structure 
var path = 'jcart', 
container = $('#jcart'), 
token = $('[name=jcartToken]').val(), 
tip = $('#jcart-tooltip'); 

var config = (function() { 
    var config = null; 
    $.ajax({ 
     url: path + '/config-loader.php', 
     data: { 
     "ajax": "true" 
     }, 
     dataType: 'json', 
     async: false, 
     success: function(response) { 
      config = response; 
     }, 
     error: function() { 
      alert('Ajax error: Edit the path in jcart.js to fix.'); 
     } 
    }); 
    return config; 
}()); 

回答

0

由于实际的Ajax请求将作出 “window.location.href +通道+ '/config-loader.php'”,你不妨将您的URL参数为:

url: location.protocol + "//" + location.host + "/folder/jcart/config-loader.php", 
1

变化var path = 'jcart',到var path = 'folder/jcart'