kennyYice23 kennyYice23 - 1 year ago 279
Ajax Question

Doing POST with AJAX returns "Response for preflight is invalid (redirect)"

I am getting a "Response for preflight is invalid (redirect)" everytime I try to execute a POST with AJAX into my webservice. I have downloaded a CORS plug in for my browser and I am able to execute a 'GET' request with it.

var $name = $("#nameTxtB");
var $order = $("#orderTxtB");
var $price = $("#priceTxtB");
var $link = "http://localhost:51834/CoffeeService.svc/addorder";

$("#addButton").on('click', function(){
var $try1 = $price.val();
var $parse = parseInt($try1);
var CoffeeOrders = {
Name: $name.val(),
Order: $order.val(),
Price: $parse,

contentType : "application/json; charset=utf-8",
dataType : 'json',
type: 'POST',
url: $link,
data: CoffeeOrders,

success: function(){
alert("Order was sucessfully created!");
error: function(){
alert("Something went wrong!");

Answer Source

The server needs to actually implement the CORS-preflight protocol if you want to make complicated requests like that. It's explained in the standard:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download