Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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 调试我的网站php文件不';不要上膛_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 调试我的网站php文件不';不要上膛

Javascript 调试我的网站php文件不';不要上膛,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我的css定义了一个类型为button submit的输入,我有一个js函数,当它被点击时使用 $(".submit").click(function(e){ if (!e.isDefaultPrevented()) { var url = "saveProfile.php"; $.ajax({ type: "POST", url: url,

我的css定义了一个类型为button submit的输入,我有一个js函数,当它被点击时使用

$(".submit").click(function(e){
    if (!e.isDefaultPrevented()) {
            var url = "saveProfile.php";

            $.ajax({
                type: "POST",
                url: url,
                data: $(this).serialize(),
                success: function (data)
                {
                    //alert('success function');
                    var messageAlert = 'my_alert-' + data.type;
                    var messageText = data.message;

                    var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';
                    var alertBox2 = '<div align="center" class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';
                    //alert(messageAlert);
                    alert('Thanks :)');

                    if (messageAlert && messageText) {
                        $('#msform').find('.result_message').html(alertBox2);
                        $('#msform')[0].reset();
                    }
                }
            });
            return false;
        }

    return false;
})
$(“.submit”)。单击(函数(e){
如果(!e.isDefaultPrevented()){
var url=“saveProfile.php”;
$.ajax({
类型:“POST”,
url:url,
数据:$(this).serialize(),
成功:功能(数据)
{
//警报(“成功功能”);
var messageAlert='my_alert-'+data.type;
var messageText=data.message;
var alertBox='×;'+messageText+'';
var alertBox2='×;'+messageText+'';
//警报(messageAlert);
警惕(‘谢谢’);
if(messageAlert&&messageText){
$('#msform').find('.result_message').html(alertBox2);
$('#msform')[0].reset();
}
}
});
返回false;
}
返回false;
})
问题是ajax函数总是失败 错误消息:未通过访问控制检查:请求的资源上不存在“访问控制允许来源”标头


我注意到:我在侧面板上看不到saveProfile.php文件-这是否意味着它没有加载?如果是,为什么?它与调用/引用它的js文件位于同一目录中

使用浏览器调试器的“网络”选项卡(例如)。这里列出了所有的请求。
如果请求成功与否,您可以看到。

< P>我认为>.php文件应该找到JS文件被调用/引用的相同目录。
您还可以在请求
标题('Access-Control-Allow-Origin:*')
中添加标题。但这可能不安全。您可以通过

saveProfile做得更好。php文件可能不在文档根目录中。在这种情况下,您应该将根目录中saveProfile.php的相对url作为url变量的值。

您是否尝试过使用chrome/firefox开发工具对其进行调试?只需转到
网络
选项卡,查看AjaxAlway添加错误功能的情况。永远不要认为你的代码会一直工作。养成使用try-catch语句的习惯。您是在本地、局域网内的计算机上还是在外部域上测试它?你使用的完整URL是什么?为什么我的答案被否决了?我认为,最好向用户展示如何调试一个猜测可能出现问题的应用程序,并给出假设问题的解决方案。