使用Ajax发布Prestashop表单 - Tools :: getValue()

时间:2017-05-17 11:15:43

标签: php jquery ajax prestashop prestashop-1.6

您好我想用ajax将表单保存到prestashop数据库中,但是我遇到了一些困难。让我告诉你我的尝试。 HTML表单:

<form action="" method="POST" class="">
    <textarea name="question_content" row="4" class="form-field"></textarea>
    <button type="submit" name="saveQuestion" id="question_ajax_save" class="button-standard">Frage abschicken</button>
</form>

JS:

$("#question_ajax_save").click(function(event) {
    event.preventDefault();
    var question = $("input[name=question_content]").val();
    if (question !==''){
        $.ajax({
            type: 'POST',
            url: baseUri + 'modules/genzo_questions/ajax.php',
            data: {
                save_question: 1,
            },
            datatype: 'json',
            success: function (response) {

                response = $.parseJSON(response);

                if (response.status === false){
                    // Do something
                }
                else {
                    // Do something
                }
            }
        });
    }
});

PHP Bridge:

if (Tools::getValue('save_question')==1) {
    echo json_encode($genzo_question->ajaxSaveQuestion());
}

在我的方法中,ajaxSaveQuestion()我想使用 Tools :: getValue('question_content')。但它是空的。为什么是这样?我可以用“data:”发送它,但在我的方法中我需要工具:getValue('id_product'),它也是空的。

简而言之:我如何在Ajax Post中使用Tools :: getValue('')?

1 个答案:

答案 0 :(得分:0)

你需要在你的ajax.php文件中添加它:

obj.Add($"column{j}", cell.Value);

然后你可以使用prestashop函数,例如:Tools :: getValue('')

我认为您忘记在代码中添加question_content:

require_once dirname(__FILE__) . '/../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../init.php';