hmahdavi
hmahdavi

Reputation: 2354

How to detect new line in result of ajax?

I get result of PartialViewResult in asp.net mvc project via ajax.When Model is null ! I pass nothing in partialViewResult but I get newline in result of ajax.How can i detect it by js?

enter image description here

 var GetSuns = function (btn) {
            $('body').append('<div class="WrapProgress"><img  class="loadingimg vertical-middle-image" src="/Content/Travelo/images/travelenter_process_Art.gif" /></div>');
            var urn = $(btn).data('urn');
            var method = $(btn).data('method');
            $.ajax({
                url: '/art/ShowTime',
                data: { s: urn, method: method },
                type: "POST",
                success: function (result) {
                    if (result.trim) {
                        console.log("1"+result+"1")
                        $('.WrapProgress').remove();
                        $('#ModalSuns .modal-body').html(result);
                        $('#ModalSuns').modal('show');
                    } else {
                        $('#Modal').modal('show');
                    }
                },
                error: function (jqXhr, textStates, errorThrown) {
                    console.log(errorThrown);
                    $('.WrapProgress').remove();
                }
            });
        };

Upvotes: 0

Views: 738

Answers (1)

SAMUEL
SAMUEL

Reputation: 8552

The issue with your code is anyway the result.trim need to changed to result.trim() inorder to trim the result string for any trailing spaces or linebreaks.

In order to detect line breaks in your code

text = `


`;
numberOfLineBreaks = (text.match(/\n/g)||[]).length;
console.log(numberOfLineBreaks)

Upvotes: 1

Related Questions