I am using the following JavaScript function to fetch the data using ajax call
function findName() {
var name = "Jhon";
$.ajax({
method: "POST",
url: "oc-content/themes/bender/ajax-test.php",
data: { name : name },
success: function (data) {
alert(data);
},
})
}
It calls the following php file and works fine.
http://127.0.0.1/osclass/oc-content/themes/bender/ajax-test.php
But when I enable SEO friendly Permalinks in my CMS current page URL is appended in start of link and I get the following error in Chrome Console.
GET http://127.0.0.1/osclass/fashion-beauty/oc-content/themes/bender/ajax-test.php?name=Jhon 404 (Not Found)
Anybody tell me how to solve this issue?
3
Answers
The url you’ve provided in the ajax call is document relative. When you changed the server’s url generation scheme, you also caused the url pointed at by the ajax call to change.
Adjust the ajax url, changing:
To:
Why don’t you make the URL server-relative? Something like this:
As you have not posted the
php
code. I would mention that any url directly navigated through addressbar of browser causes in theGET
request and i can see you have aPOST
request in the ajax, so, it can’t work.Workaround would be to use
$_REQUEST
super globals at php end.$_REQUEST
would work for$_GET/$_POST
requests.