1

I have this structure: HTML:

<input type="submit" name="_ninja_forms_field_7" class="ninja-forms-field  popup-submit" id="ninja_forms_field_7" value="" rel="7">

JS:

$('#ninja_forms_field_7').click(function () {
    var name = $('#ninja_forms_field_6').val();
    var surname = $('#ninja_forms_field_6').val();
    var emailAddress = $('#ninja_forms_field_8').val();
    var eCommerceSiteUrl = $('#ninja_forms_field_9').val();




    var post_datas = emailAddress = +emailAddress+ & name = +name+ & surname = +surname+ & eCommerceSiteUrl = +eCommerceSiteUrl;
    $.ajax({
        type: 'POST',
        url: 'myserviceaddress',
        data: post_datas,
        success: function (answer) {
            console.log(answer);
        }
    });
});

It working good. But I want, If service response code 0, parse a text in page.

How can I do it?

mehmet
  • 11
  • 2

1 Answers1

0

Just add the error: function() lines you see below beneath success:

$.ajax({
    type: 'POST',
    url: 'myserviceaddress',
    data: post_datas,
    success: function (answer) {
        console.log(answer);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        $("#result_div").html("textStatus");
    }
});

Also, make sure you create a <div id="result_div"></div> so that the JQuery has a place to put the result in.

M -
  • 26,908
  • 11
  • 49
  • 81
  • Thanks. Yes, error function is working but not I want this. I have many codes in service so generate text by response code. No one error code. – mehmet Jun 02 '15 at 21:41
  • Have you looked at the top answer in this question? It seems to address the same issue you're having: http://stackoverflow.com/questions/5344145/how-to-get-response-status-code-from-jquery-ajax – M - Jun 02 '15 at 21:53