有没有一种方法可以用PHP / AJAX返回不仅仅是文本?

时间:2019-02-02 15:26:25

标签: javascript php ajax

我正在尝试从PHP表单处理代码中更改AJAX代码中的'$ .notify'样式。我需要它来返回“成功”或“错误”。

这是我的AJAX代码示例:

<h1>Kroger Save Page..</h1>
<p> <%= @products.length %> products in Smith DB.</p>
<p> <%= @divs.length %> divs scraped. </p>
<p> <%= @spans.length %> spans products scraped. </p>
<p> <%= @body.text %> </p>
<p> <%= @p.length %> ps scraped.</p>
<p> <%= @li.length %> lis scraped.</p>
<p> <%= @li.first.divs.length %> divs nested in lis scraped.</p>
<p> <%= @li.first.ps.length %> ps nested in lis scraped.</p>

这是我的PHP代码的示例:

    $(function() {
        $("#name-submit").submit(function(event) {
            event.preventDefault();
            if ($("#name").val() != "") {
                $.ajax({
                    method: "POST",
                    url: "<?=updateNameFile?>",
                    data: {
                        name: $("#name").val()
                    }
                }).done(function(msg) {
                    $.notify(msg, "success");
                });
            } else {
                $.notify("<?php echo $language_form_message_invalid_data; ?>", "error");
            }
        });
    });

同样,我需要它在我的AJAX代码中返回“错误”或“成功”,以正确设置通知的样式。

0 个答案:

没有答案