Как я могу отобразить ошибку, представленную JSON через AJAX?

Не лучшая практика ... но отлично работает ...

<ComboBox GotFocus="Focused"  x:Name="combobox1" HorizontalAlignment="Left" Margin="8,29,0,0" VerticalAlignment="Top" Width="128" Height="117"/>

Код за

public partial class MainWindow : Window
{
    bool clearonce = true;
    bool fillonce = true;
    public MainWindow()
    {
        this.InitializeComponent();          
        combobox1.Items.Insert(0, " -- Select Team --");
        combobox1.SelectedIndex = 0;
    }

    private void Focused(object sender, RoutedEventArgs e)
    {
            if(clearonce)
            {
                combobox1.Items.Clear();
                clearonce = false;
            }
            if (fillonce)
            {
              //fill the combobox items here 
                for (int i = 0; i < 10; i++)
                {
                    combobox1.Items.Insert(i, i);
                }
                fillonce = false;
            }           
    }
}
0
задан Gagan 7 March 2019 в 02:29
поделиться

2 ответа

Вы можете сделать следующее

  if (data.errors){
        for (let key in data.errors) {
                        $('#' + data.errors[key][0] + '-error').text(data.errors[key][1]);  // key in your case is email,password2
                    }
                return false;
}

В html

<div class="form-group">
                <label for="name">Name*</label>
                <input class="form-control" id="name" required="required" name="name" type="text" value="">
                <span class="error" id="name-error"></span>
            </div>
            <div class="form-group">
                <label for="contact-email">Email*</label>
                <input class="form-control" id="email" required="required" name="email" type="text" value="">
                <span class="error" id="email-error"></span>  // here id is email-error so you must must email key in error return by server.
            </div>

. В этом случае помните, что id в span и key на стороне сервера должны совпадать. Надеюсь, это поможет.

0
ответ дан Sundar Ban 7 March 2019 в 02:29
поделиться

Вы можете использовать проверку на стороне клиента, чтобы убедиться, что введены правильные данные.

0
ответ дан Adam Howard 7 March 2019 в 02:29
поделиться
Другие вопросы по тегам:

Похожие вопросы: