Helper Helper - 1 year ago 137
Ajax Question

Posting data via JQuery Ajax

I am facing issue in Posting data using JQuery. It works fine when I do it through Chrome Extension Postman.

My Code

var request = $.ajax({
url: '',
type: "POST",
data: {Role : "wsed"},
async: true,
contentType: "application/json; charset=utf-8",
"X-Requested-With": "XMLHttpRequest"

request.done(function(msg) {
});, textStatus) {


contentType: "application/json; charset=utf-8"

X-Requested-With: "XMLHttpRequest"

Works fine when posted data with Postman Chrome Extension. Screenshot below

enter image description here

Answer Source

Please try this

    "async": true,
    "crossDomain": true,
    "url": "",
    "method": "POST",
    "headers": {
        "content-type": "application/x-www-form-urlencoded",
        "x-requested-with": "XMLHttpRequest",
    "data": {
        "Role": "wsed"
    success: function (msg) {
    error: function (jqXHR, textStatus) {

I see error in console Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at (Reason: CORS header 'Access-Control-Allow-Origin' missing).

for that please allow cross origin by placig this code in your root .htaccess

<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"

for more info to allow cros origin please refer this link

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