I am trying to login to my wordpress site using ajax call, which i asked in previous question. It should not respond anything back. But whenever i call this ajax function, Firefox(firebug) is showing 200 OK in red. This must be a cross domain issue. Tried too many things but no luck so far. Here is the code:
$.ajax({
type: "POST",
url: "http://path-to-wordpress/wp-login.php",
data:myData
success: function(data){
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
Any suggestion will be appreciated.
I assume your JS code is on
abc.com
and your wordpress site isdev.abc.com
.To fix cross domain issue, just add the following code to
.htaccess
file to your wordpress site (dev.abc.com
)Just replace
(abc.com)
with a proper site name. For eg:(google.com)
or(yahoo.com)
Set the dataType to
JSONP
, in your ajax call and it will work cross-domainFor refrence ot ajax call visit jQuery Ajax
There is property named crossDomain of $.ajax. Please set it to true.
You need to add CORS headers in you
wp-login.php
page.Here’s how to do it
But given the nature of the page, be extra cautious : don’t allow all origins (*) but only your site. If you allow all, your users could have their login info stolen.