0

i have used all the Ajax code but it gives some error like "XMLhttprequest can not load" after using the "access-control-allow-origin: '*'" in my java script code it gives some another error like "unexpected error" . i have searched on internet last 3-4 days but i am not getting any solution finally i am here guys please help me to solve this problem .

This is my code:`

jQuery.noConflict();
jQuery(document).ready(function( $ ){

var encryptedText = "hdEAo+i4qK9UmgYlbHE490RFcqq";
new Ajax.Request('http://example.com/json/service', {
access-control-allow-origin: '*',
method: 'post', 
contentType: 'application/json',    
postBody: '{"abc":{"request":'+encryptedText+'}}',
onSuccess: function(transport){
var myObject = eval('(' + transport.responseText + ')');
        alert("success");   
            },  
OnFailure : function(){
        alert("fail");
                },
        });
    });`

i have also used prototype.js in my project.

i don't have any idea about "access-control-allow-origin" code where i put in my code please tell me .

Please give me with coding not only theory guys because i am new in this field.

i will really appreciate all guys who solve this problem.

  • 1
    *"i don't have any idea about "access-control-allow-origin" code where i put in my code"* That is something the **server** has to add to allow XMLHTTPRequests to it. If it doesn't do that, you simply cannot do an XMLHTTPRequest to it. See [Ways to circumvent the same-origin policy](http://stackoverflow.com/q/3076414/218196) for more info. – Felix Kling Jun 02 '16 at 04:33
  • i need to host my project on server or not i am not understanding .can i run XMLhttprequest in my localhost tomcat server. – somesh kumar Jun 02 '16 at 04:57
  • You first need to understand what the *same origin policy* and *cross origin resource sharing (cors)* are. Wikipedia has articles for both. Then you can look for a potential solution. – Felix Kling Jun 02 '16 at 05:51

0 Answers0