1

Hello i am working on a PHP script and i am facing an issue that when i open the URL from browser it opens successfully but when try to make ajax request it gives me 404 Error. My Code is Following

jQuery.ajax({
            url : "http://example.com/ajaxRequest/index.php",
            method : "POST",
            cache: false,
            data : {
                name : "Mohsin",
            },
            success : function(data){
                alert(data);         
            },
        });

Same URL opens in browser but gives 404 Error with ajax Request. i have also included

header('Access-Control-Allow-Origin: *');

in above script

Muhammad Husnain Tahir
  • 1,009
  • 1
  • 15
  • 28

1 Answers1

1

Mention as cross domain request in your ajax. And also use jsonp for cross domain requests.

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);         
        },

See about jsonp here and here

Community
  • 1
  • 1
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41