Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 XHR请求已完成,但未正确捕获变量_Javascript_Php_Ajax_Xmlhttprequest - Fatal编程技术网

Javascript XHR请求已完成,但未正确捕获变量

Javascript XHR请求已完成,但未正确捕获变量,javascript,php,ajax,xmlhttprequest,Javascript,Php,Ajax,Xmlhttprequest,这是我的密码: $(function() { $('#button-cart').on('click', function() { $.ajax({ url: "shop/system/library/cart.php?csp=" + $('#input-custom-price').val(), success: function(data) { console.log($('#input-

这是我的密码:

$(function() {
    $('#button-cart').on('click', function() {
        $.ajax({
            url: "shop/system/library/cart.php?csp=" + $('#input-custom-price').val(),
            success: function(data) {
                console.log($('#input-custom-price').val());
            }
        });
    });
});
在这种情况下,当我将此变量发送到我自己的php时,我可以使用GET读取该变量:

$csp = $_GET['csp'];
这是完美的工作。 但是,当我尝试发送到cart.php(一个opencart文件)时,我总是会收到一个错误: 注意:未定义索引:csp在。。。在线314 所以我编辑了我的代码:

$csp = (isset($_GET['csp']) ? $_GET['csp'] : 10);

现在没有错误消息,但是php总是用10计算。有什么想法吗?

请求在控制台中看起来如何?Chrome的开发工具真的可以让XHR完成加载:获取http://**************/shop/system/library/cart.php?csp=100。是否涉及重定向或Apache重写规则?他们可能会杀了那些警察。您可能希望在AJAX请求中尝试使用POST而不是GET。但是,当我将此请求发送到另一个php时,没有什么特别有效的方法。RewriteBase/RewriteRule^sitemap.xml$index.php?route=feed/google\u sitemap[L]RewriteRule^googlebase.xml$index.php?route=feed/google\u base[L]RewriteRule^download/*/index.php?route=error/not\u found[L]RewriteCond%{REQUEST\u FILENAME}-f RewriteCond%{REQUEST_FILENAME}-已重写条件%{REQUEST\u URI}!。*\。ico | gif | jpg | jpg | png | js | css RewriteRule ^[^?]*index.php?(u route)=$1[L,QSA]试试这篇文章,尽量消除这种可能性。还可以尝试使用var_dump$服务器;死亡以确保正确获取URL。