kshan 2k18
kshan 2k18

Reputation: 1

Call php function from same file using javascript

I have a requirement to display contents of a file after clicking it. I am using javascript to call the php function in same file using Ajax. I know we cannot call php function using Ajax but i am trying to call the same file and in php file i am checking the isset() for the parameter which i am sending through ajax. I dont know whats wrong but the code is not working. Can someone please assist me>=?

PHP code am using...

    if(isset($_POST['param3'])){
           echo "I am in displaying data successfull ajax call";
    }

My ajax:

$.ajax({
    type:'POST',
    url : 'surveypanel.php',
    data : {param3:"asdf"},
    success : function(data){
        //
    }
});

Thanks, Kshan

Upvotes: 0

Views: 594

Answers (1)

JoinCompany
JoinCompany

Reputation: 514

try this:

$.ajax({
    type:'POST',
    url : 'surveypanel.php',
    data : {param3:"asdf"},
    success : function(data){
        // use data for get response from surveypanel.php
        alert(data);
    }
});

Upvotes: 2

Related Questions