I have a JavaScript script:
$("#feedbacksubmit").click(function() {
if($("#frmfeedback").valid()) {
var tname = $("#name").val();
var temail = $("#email").val();
var tphone = $("#phone").val();
var tcontent = $("#content").val();
var tsend = $(this).attr('ts');
$.post ( "bll/index.php",
{ action: 'mailfeedback', name: tname, email: temail, phone: tphone, content: tcontent, send: tsend },
function(data) {
$('.msgbox').html(data);
$("#frmfeedback")[0].reset();
});
return false;
}
});
However, I am trying to see if there is a way to access the class method of bll/index.php directly from the script, instead of posting parameters, to access it.
It sounds like you’re getting confused with developing on the web.
JavaScript (unless specified) is a “client-side” language, meaning that it runs on the clients browser AFTER has page has been compiled and sent from the server. This means that there is no PHP/ASP in the code, only HTML and JavaScript.
PHP, ASP, JSP are server-side languages which only run on the server-side.
So to answer your question, no, you can’t directly get the JavaScript to call a PHP (server-side) function, but you can post to a PHP page which will then in turn carry out whatever function you like.
Now if you are saying is it possible (Although it’s not recommendable ) then my answer is:–
YES
Calling PHP methods from JavaScript is possible by using XML-RPC. You can call PHP methods remotely with JavaScript by setting up an XML-RPC server (a PHP page) and then access that server within JavaScript. There are PHP XML-RPC libraries and JavaScript XML-RPC .js files.
In computer science everything is possible.
Google it for more details.