I am using jquery's AJAX in my project. Today, I used it somewhere else with all same themethods but it doesn't work.

Is there something wrong with my script?

HTML:

<a class='btn edit_receipe_btn' id='myreceipe-52'>Edit</a>

JQuery:

(Click function works. When I put alert(instance) after var instance line, it works)

$(document).ready(function(){
$('.edit_receipe_btn').click(function(){
   var instance = $(this).attr('id');
   var dataString = 'process=userReceipeEdit&instance='+instance;
   $.ajax({
    type: 'POST',
    url: 'ajax/ajaxs.php',
    data: dataString,
    cache: false,
    success: function(msg) {
        alert(msg);
    }
    });
});
});

PHP:

$prcs = $_POST['process'];
if($prcs=='userReceipeEdit'){
        $instance = $_POST['instance'];
        return $instance;
    }

It appears the problem is in the PHP. What am I doing wrong?

Comments

You do have $prcs = $_POST['process']; in your PHP as well, yes?

Written by sje397

Yeah, I just added it to my post. It was there from the beginning in my code.

Written by xy_

if you take out that if $prcs statement can you hit the page directly in a browser?

Written by wajiw

print_r($_POST); and show us what PHP is receiving.

Written by dnagirl

@wajiw no you can't hit directly in a browser. But there are 3 other conditions which are using $prcs in my script. All other works with no problem. Just this one.

Written by xy_

@dnagirl here is result, it looks OK: Array ( [process] => userReceipeEdit [instance] => myreceipe-52 )

Written by xy_

Is that the entire PHP page? if so, you should echo instead of return

Written by Jasper De Bruijn

@Jasper oh my brain blowed at the end I think :) Yeah you are right. How can't I see. Thank you so much.

Written by xy_

Please don't put 'solved' in the title. If something someone else wrote solved your problem, please upvote and accept their answer.

Written by George Stocker

@George I wrote solved because Jasper didn't answered my question. The answer was in comments. I didn't want people to waste time on a solved topic. Should I still remove it? I answered myself but I cant accept it in 2 days.

Written by xy_

You should move whatever solved it to an answer, and in two days time upvote it.

Written by George Stocker

@jasper you should have written that as an answer.

Written by George Stocker

@George ok I will do that, thanks.

Written by xy_

I posted as an answer, for the sake of it

Written by Jasper De Bruijn

Accepted Answer

Is that the entire PHP page? if so, you should echo instead of return

Written by Jasper De Bruijn
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki