2

I am doing simple post request through jquery and reading data from it on localhost.

My script works ok if i access the file through localhost , but if i access the file by double clicking it on console it says me 200 ok in red text and i dont get any response . My file name is send.html and it is sending data through jquery . my code is

<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script>
$(document).ready(function (){  
                    var counter =1 , array_counter =0;
                    var picture_id_array=new Array(6);
                    picture_id_array[1] = new Array(3);
                    $.ajax({   
                        type: "POST",
                        data : $(this).serialize(),
                        cache: false, 
                        url: "http://localhost/CI/index.php/page/id/1",   
                        success: function(data){
                            var obj = jQuery.parseJSON(data);
                       var json = $.parseJSON(data);
                       $(json).each(function(i,val){
                            $.each(val,function(k,v){
                             console.log(k+" : "+ v);    
                            }
                          });
                  });

it says me about this line in jquery cause the error

 // Do send the request
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)
xhr.send( ( s.hasContent && s.data ) || null );

I tried one solution which is to putt datatype:JSONP but it didnt give me the result .

Uahmed
  • 1,847
  • 5
  • 29
  • 45
  • 1
    possible duplicate of [localhost :: cross domain ajax](http://stackoverflow.com/questions/3849200/localhost-cross-domain-ajax) or [XMLHttpRequest Origin null is not allowed Access-Control-Access-Allow for file:/// to file:/// (Serverless)](http://stackoverflow.com/q/4208530/1048572)? – Bergi Mar 26 '13 at 13:35
  • 1
    Since you're opening a local file (`file://`), your browser will block requests performed to another 'domain' (`http://`) because that's considered to be a security risk (it's called a 'cross-domain request', and is described [here](http://en.wikipedia.org/wiki/Same_origin_policy)). – robertklep Mar 26 '13 at 13:38
  • Thanks for the reply it was cross-domain request issue . – Uahmed Mar 27 '13 at 08:50

0 Answers0