0

//

Blockquote I am trying to access the json contents through a Web API. I can access the contents but for some reason it gives me errors : "no 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access." Now it means that I have to enable some how the CORS or by moving the contents to the same domain.

I am not sure if I have to enable it On a: Origin Server (Requesting) in this case localhost b: On the external server OR c: I have to set up some code in my ajax call

Please advise and guide to right content as I am a bit of ******* in this regard.

<script>
        jQuery(document).ready(function() {
            jQuery('#34f8l4frywio').change(function(){
                if((jQuery("#34f8l4frywio").length < 0) || (jQuery("#vnkt3fpocr10").length < 0)){

                }else{
                    var newserial = jQuery("#34f8l4frywio").val();
                    var newmodel = jQuery("#vnkt3fpocr10").val();
                    jQuery.ajax({
                        url : 'http://example.com/xmlrpc/serial_json.php?serial='+ newserial+'&model='+ newmodel + '&format=json',

                        dataType: "text",
                        contentType: "text/plain",
                        xhrFields: {
                            withCredentials: false
                            }, 
                         //here it fails and gives the error
                        success: function(data) {
                            var json = $.parseJSON(data);

                                jQuery('#6bun045yhogr').val(json[0].warranty);
                                jQuery('#34f8l4frywio').val(json[0].serial);
                                jQuery("#vnkt3fpocr10").val(json[0].model);
                        }
                    });
                }
            });
        });
    </script>
Emir
  • 1
  • 3

1 Answers1

0

Refer Angular.js No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access

"Access-Control-Allow-Origin is set on the response from server, not on client request to allow clients from different origins to have access to the response."

Community
  • 1
  • 1