Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XMLHttpRequest cannot load http://myApiUrl/login. No
- 'Access-Control-Allow-Origin' header is present on the requested
- resource. Origin 'null' is therefore not allowed access.
- $.ajax({
- type: "POST",
- dataType: 'text',
- url: api,
- username: 'user',
- password: 'pass',
- crossDomain : true,
- xhrFields: {
- withCredentials: true
- }
- })
- .done(function( data ) {
- console.log("done");
- })
- .fail( function(xhr, textStatus, errorThrown) {
- alert(xhr.responseText);
- alert(textStatus);
- });
- chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security
- $.ajax({
- type: "POST",
- dataType: 'jsonp',
- ...... etc ....
- <?php header('Access-Control-Allow-Origin: *'); ?>
- app.use(function(req, res, next) {
- res.header("Access-Control-Allow-Origin", "*");
- res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- next();
- });
- <cffunction name="optionsMethod" access="remote" output="false" returntype="any" httpmethod="OPTIONS" description="Method to respond to AngularJS trial call">
- <cfheader name="Access-Control-Allow-Headers" value="Content-Type,x-requested-with,Authorization,Access-Control-Allow-Origin">
- <cfheader name="Access-Control-Allow-Methods" value="GET,OPTIONS">
- <cfheader name="Access-Control-Allow-Origin" value="*">
- <cfheader name="Access-Control-Max-Age" value="360">
- </cffunction>
- Spark.get("/someRestCallToSpark", (req, res) -> {
- res.header("Access-Control-Allow-Origin", "*"); //important, otherwise its not working
- return "some text";
- });
- Ext.Ajax.request({
- url: "http://localhost:4567/someRestCallToSpark",
- useDefaultXhrHeader: false, //important, otherwise its not working
- success: function(response, opts) {console.log("success")},
- failure: function(response, opts) {console.log("failure")}
- });
- using (DBContext db = new DBContext())
- {
- return db.Customers.Select(x => new
- {
- Name = x.Name,
- CustomerId = x.CustomerId,
- });
- }
- using (DBContext db = new DBContext())
- {
- return db.Customers.Select(x => new
- {
- Name = x.Name,
- CustomerId = x.CustomerId,
- }).ToList();
- }
- @GET
- @Path("{id}")
- public Response getEventData(@PathParam("id") String id) throws FileNotFoundException {
- InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/eventdata/" + id + ".json");
- JsonReader jsonReader = Json.createReader(inputStream);
- return Response.ok(jsonReader.readObject()).header("Access-Control-Allow-Origin", "*").build();
- }
- $.ajax({
- type: "POST",
- dataType: 'text',
- url: https://crossorigin.me/api,
- username: 'user',
- password: 'pass',
- crossDomain : true,
- xhrFields: {
- withCredentials: true
- }
- })
- .done(function( data ) {
- console.log("done");
- })
- .fail( function(xhr, textStatus, errorThrown) {
- alert(xhr.responseText);
- alert(textStatus);
- });
- <filter>
- <filter-name>CORS</filter-name>
- <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>CORS</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --allow-file-access-from-files
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement