简体   繁体   English

Ajax调用返回“找不到”错误

[英]Ajax call returning “Not Found” Error

This SHOULD be very simple, but my ajax call is returning a "Not Found" error. 这应该非常简单,但是我的ajax调用返回“找不到”错误。 I've searched for similar issues, and tried the various suggestions, but to no avail. 我已经搜索了类似的问题,并尝试了各种建议,但无济于事。

Front-end logic 前端逻辑

(function($) {
    $(document).ready(function() {
        // ----------
        // Instant Quote Form
        // ----------
        $('.instant-form').submit(function() {
            $('.error').html('').hide();
            var var_url = $(this).attr('action');
            var var_data = $(this).serialize();
            var elem = this;
            var err = 0;
            var msg = '';

            alert("Driver Form Submitted: " + var_data);
            alert("Action: " + var_url);

            $.ajax({
                type: 'POST',
                url: var_url,
                data: var_data,
                dataType: 'text',
                async: false,
                success: function(data, status, jqXHR) {
                    alert("Returned : " + data);
                },
                error: function(jqXHR, status, error) {
                    alert('FAILURE: status =' + status + ' error=' + error);
                }
            });

            return false;
        });
    });
})(jQuery);

The Alert showing the URL is as follows: 显示URL的警报如下:

Action: http://www.professionaldrivers.com/wp-content/themes/professionaldrivers/aqs/get-quote.php 行动: http//www.professionaldrivers.com/wp-content/themes/professionaldrivers/aqs/get-quote.php

If I enter the displayed URL in the browser, the php file is executed, so I know I have the correct path 如果我在浏览器中输入显示的URL,则将执行php文件,因此我知道我的路径正确

Finally, I cut everything out of the PHP file for now. 最后,我暂时将所有内容从PHP文件中删除。 So it only consists of: 因此,它仅包含:

Back-end logic 后端逻辑

<?php require('./../../../../wp-blog-header.php');
header('Content-Type: application/json');   
if(!isset($_POST['action']))
    die('horrible death');   
ini_set('display_errors', '1');
die();
?>

Any ideas or suggestions would be greatly appreciated! 任何想法或建议,将不胜感激!

这似乎可行,将代码粘贴到js小提琴中http://jsfxxx.net/da4xyL1f/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM