J查询ajax,获取未定义的值

时间:2017-01-17 13:34:48

标签: jquery ajax

我仍然试图解决它几天。我尝试过很多东西,但没有人工作过:

这是代码

 $(document).ready(function(){
    $("#buttonclick").click(function () {
        var myval = {
            FirstName: $('#TxtFirstNamePhysician').val(),
            LastName: $('#TxtLastNamePhysician').val(),
            EmailId: $('#TxtEmailIdPhysician').val(),
            Password: $('#TxtPasswordPhysician').val(),
            PhoneNumber: $('#TxtPhoneNoPhysician').val()
        };

        $.ajax({
            url: "http://localhost:49956/Physician_Registration/Physician_Reg",
            type: 'POST',
            data: myval,
            dataType: "text",
            success: function (data) {
                alert(data.responseText);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
        });
    });
});

它说未定义。

This Is what is the error i am getting

2 个答案:

答案 0 :(得分:0)

尝试传递正确的内容类型。 如果没有工作,那么通过将myval对象转换为json来尝试它。并将内容类型作为application / json传递。

答案 1 :(得分:0)

我相信这是因为你的html没有正确标记。

我已经制作了一个工作样本,请转到下面的jsfiddle。

<body>
<form>
<label for="first-name">First Name</label>
<input name="first-name" id="TxtFirstNamePhysician" /><br>
<label for="last-name">Last Name</label>
<input name="last-name" id="TxtLastNamePhysician" /><br>
<label for="email">Email</label>
<input name="email" id="TxtEmailIdPhysician" /><br>
<label for="password">Password</label>
<input type="password" name="password" id="TxtPasswordPhysician" /><br>
<label for="phone-number">Phone Number</label>
<input name="phone-number" id="TxtPhoneNoPhysician" /><br>
<input type="button" value="submit" id="buttonclick" />
</form>
<div class="output">
</div>
</body>

Working Sample in JSFiddle