In my php code I am using following Ajax request. The Ajax request showing following error in Chrome browser console
XMLHttpRequest cannot load http://example.com/posts. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. (index):
My code :
<script>
$(document).ready(function() {
var title = 'Tes ajax';
var raw = 'very good';
//Validate fields if required using jQuery
var postForm = { //Fetch form data
'api_key' : 'bf_apikey',
'api_username': 'username',
'title' : title,
'raw' : raw,
'category' :'categoryname'//Store name fields value
};
$.ajax({ //Process the form using $.ajax()
type : 'POST', //Method type
url : 'http://example.com/posts', //Your form processing file URL
data : postForm, //Forms name
dataType : 'application/json',
success: updatesuccess,
error: updatefailure
// return response; // <- tried that one as well
});
function updatesuccess(result)
{
alert(result+"Successs")
}
function updatefailure()
{
alert("failure")
}
});
</script>
please suggest better option to solve this error.