1

That is my function:

function deleteAutoAd(id, title) {
    alert(title);                                                                         
    $.ajax({
        dataType: 'json',
        url: '/ajax/deleteautoad',
        type: 'POST',
        data: {
            id : id,
            title : title
        },
        success: function(data) {
            alert(data);
        }
    });
}

In this function when I try alert(title) and popup 'This is title'(because title = 'This is title'). But in ajax/deleteautoad I try this:

public function deleteautoadAction() {
    if ($this->getRequest()->isPost()) {
        echo $param1 = $this->_request->getParam('id');
        echo $param2 = $this->_request->getParam('title');
    }
}

Echo param1 show 5, but echo param2 don't show nothing.

3
  • check var_dump($_POST) to see what is posted. Also check in your browser what data is posted. Commented Aug 28, 2012 at 21:05
  • I try var_dump($_POST), but don't do nothing I don't know why, with HttpFox I found this post and postdata is: id=4&&title=This is title Commented Aug 28, 2012 at 21:10
  • I have tested your code and deleteautoadAction echoes id and title. Commented Aug 29, 2012 at 6:35

4 Answers 4

2

i think you should try :

function deleteAutoAd(id, title) {
    alert(title);                                                                         
    $.ajax({
        dataType: 'json',
        url: '/ajax/deleteautoad',
        type: 'POST',
        data: {
            'id' : id, // Note the quotes
            'title' : title // Note the quotes
        },
        success: function(data) {
            alert(data);
        }
    });
}

regards

mimiz

Sign up to request clarification or add additional context in comments.

1 Comment

Before I post my question I try this and don't have results
1

I agree with the above answer

Also, For my application, I also have to post the full url. So you might want to try

var root = location.protocol + '//' + location.host;

and then on your url

url: root+'/ajax/deleteautoad',

2 Comments

Although, in hindsight, my application is 'widgetised' so these things can be called from anywhere ... which probably explains why I use static urls. (it's been a while since I worked on that area)
I try this and that from previos previous post but don't have result only echo id, but title don't.
1

You should return from controller a valid JSON with Success status.

public function deleteautoadAction() {
    if ($this->getRequest()->isPost()) {
        $x->Status = 'Success';
        $x->Message = $this->_getParam('id') . $this->_getParam('title');
        $this->_helper->json($x);
    }
}

And also you should change your alert statement

function deleteAutoAd(id, title) {
    $.ajax({
        dataType: 'json',
        url: '/ajax/deleteautoad',
        type: 'POST',
        data: {
            id : id,
            title : title
        },
        success: function(data) {
            alert(data.Message);
        }
    });
}

1 Comment

Now alert id and title, but I need to use title value in my action. How to get title I try $this->_request->getParam('title'); but don't have result
0

Moved from the OP question to a CW answer:

I fixed the problem by removing: dataType: 'json'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.