Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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在浏览器中工作正常,但在ajax请求中出现404错误_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript URL在浏览器中工作正常,但在ajax请求中出现404错误

Javascript URL在浏览器中工作正常,但在ajax请求中出现404错误,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,您好,我正在编写一个PHP脚本,我面临一个问题,当我从浏览器中打开URL时,它会成功打开,但当尝试发出ajax请求时,它会给我404错误。我的代码如下 jQuery.ajax({ url : "http://example.com/ajaxRequest/index.php", method : "POST", cache: false, data : { name :

您好,我正在编写一个PHP脚本,我面临一个问题,当我从浏览器中打开URL时,它会成功打开,但当尝试发出ajax请求时,它会给我404错误。我的代码如下

jQuery.ajax({
            url : "http://example.com/ajaxRequest/index.php",
            method : "POST",
            cache: false,
            data : {
                name : "Mohsin",
            },
            success : function(data){
                alert(data);         
            },
        });
相同的URL在浏览器中打开,但ajax请求出现404错误。我还包括

标题('Access-Control-Allow-Origin:')


在上面的脚本中,提到ajax中的跨域请求。还可以使用
jsonp
进行跨域请求

url : "http://example.com/ajaxRequest/index.php",
        method : "POST",
        cache: false,
        data : {
            name : "Mohsin",
        },
        crossDomain:true,    <---- add this line
         dataType : 'jsonp',   // also this line
        success : function(data){
            alert(data);         
        },
url:http://example.com/ajaxRequest/index.php",
方法:“张贴”,
cache:false,
数据:{
姓名:“莫辛”,
},

crossDomain:是的,这是一个跨源请求吗?是的,这是跨源请求。如果显示任何请求,请在控制台中进行检查errors@syedmohamed是的,它给出了404找不到错误。你能确认你收到了cors总部吗?欢迎你。试试看,让我知道结果。是的,当然:)。。我会让你知道JSONP是一种黑客,在这种情况下不需要访问服务器端代码。它还需要在服务器上重新编码