Мой веб-сервис не работает или не работает - PullRequest
0 голосов
/ 04 декабря 2018

Я хочу вставить данные в базу данных с помощью веб-службы, но AJAX не вызывает веб-службу.

HTML-КОД

<form id="form1">
            <div>  <input type="text" name="name2" runat="server"  id="Text12" placeholder="Your Name" />
                <input type="button" value="Save Data" onclick="SendD()" id="send1" />
                </div>
                </form>

AJAX-КОДИРОВАНИЕ:

function SendD() {
    var name = document.getElementById('Text12').value;

    alert();


        $.ajax({
            type: "POST",
            url: "Web2.asmx/Data2",
            data: "{Namen: '" + name + "'}", // here we are specifing the data as a JSON object, not a string in JSON format
            // this will be converted into a form encoded format by jQuery
            // even though data is a JSON object, jQuery will convert it to "firstName=Aidy&lastName=F" so it *is* form encoded
            contentType: "application/json; charset=utf-8", // we are sending in JSON format so we need to specify this
            dataType: "json", // the data type we want back. The data will come back in JSON format
            async: false,
            success: function (data) {
                alert("Succes");

            },
            failure: function (data) {

                alert("F");
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            }
        });


}

Код веб-службы работает нормально

[WebMethod]
    public static string Data2(String Namen)
    {
        string json = "";

        string connstr = ConfigurationManager.ConnectionStrings["DBL"].ConnectionString;
        SqlConnection conn = new SqlConnection(connstr);
        conn.Open();

        //insert into Claim_Status_Trans(Claim_ID,Claim_Status,Status,Deleted_Flag,Row_upd_date)values(@claimid,7,1,0,@rowupddate)
        string qry1 = "insert into SendDataTable(Name)values('" + Namen + "')";
        SqlCommand movestoclaims = new SqlCommand(qry1, conn);
        movestoclaims.ExecuteNonQuery();
        conn.Close();
        return json;

    }

Заранее спасибо

Я пытаюсь проверить, работает ли кнопка оповещения, работает ли нормально только ajax, не вызывающий веб-службу.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...