CORS enabled but response for preflight has invalid HTTP status code 404 when POSTing JSON

Thanks but getting 405 error,after the above config changes. Finally it works after adding below code in web api Global.asax file protected void Application_BeginRequest(Object sender, EventArgs e) { //HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Origin”, “*”); if (HttpContext.Current.Request.HttpMethod == “OPTIONS”) { HttpContext.Current.Response.AddHeader(“Cache-Control”, “no-cache”); HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Methods”, “GET, POST”); HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Headers”, “Content-Type, Accept”); HttpContext.Current.Response.AddHeader(“Access-Control-Max-Age”, “1728000”); HttpContext.Current.Response.End(); } }

XMLHttpRequest testing in Jest

The jest api has changed a bit. This is what I use. It doesn’t do anything but it’s enough to render my components. const xhrMockClass = () => ({ open : jest.fn(), send : jest.fn(), setRequestHeader: jest.fn() }) window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass) and in the test file: import ‘../../__mock__/xhr-mock.js’

Python Flask Cors Issue

After I tried others suggestions and answers. Here’s what I use, which works. Steps: pip install flask flask-cors Copy and paste this in app.py file Code from flask import Flask, jsonify from flask_cors import CORS, cross_origin app = Flask(__name__) CORS(app, support_credentials=True) @app.route(“/login”) @cross_origin(supports_credentials=True) def login(): return jsonify({‘success’: ‘ok’}) if __name__ == “__main__”: app.run(host=”0.0.0.0″, port=8000, debug=True) … Read more

How to Load Ajax in WordPress

As per your request I have put this in an answer for you. As Hieu Nguyen suggested in his answer, you can use the ajaxurl javascript variable to reference the admin-ajax.php file. However this variable is not declared on the frontend. It is simple to declare this on the front end, by putting the following … Read more

How can I change the URI without refreshing the page?

In HTML5 you can change the URL: window.history.pushState(“object or string”, “Title”, “/new-url”); check http://spoiledmilk.com/blog/html5-changing-the-browser-url-without-refreshing-page/ docs: https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState().c2.a0method UPDATE An overview of which browser support the new HTML5 history API: http://caniuse.com/#search=pushState (caniuse.com is worth to bookmark!) there are already frameworks that do the hard work for you and even gracefully fallback to the common hash-tag solution: History.js … Read more

Reading JSON from SimpleHTTPServer Post data

Thanks matthewatabet for the klein idea. I figured a way to implement it using BaseHTTPHandler. The code below. from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import SocketServer import simplejson import random class S(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header(‘Content-type’, ‘text/html’) self.end_headers() def do_GET(self): self._set_headers() f = open(“index.html”, “r”) self.wfile.write(f.read()) def do_HEAD(self): self._set_headers() def do_POST(self): self._set_headers() print “in post method” … Read more