I've built a test client page and I'm trying to post to a Web API that I've built, but I get the following error:
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'val'
on the following code:
<!DOCTYPE html>
<html xmlns="">
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnSubmit").click(function () {
var user = {
email: ('#txtEmail').val(),
password: ('#txtPassword').val(),
firstName: ('#txtFirstName').val(),
lastName: ('#txtLastName').val(),
country: ('#txtCountry').val(),
postal: ('#txtPostal').val()
};
$.post("http://myUrl/api/****/***************", user, function (data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
I can hit the service in Fiddler with the intended result, so I don't think its my service.
Also, I found a question on Stack talking about a similar issue regarding changing:
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
to
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js" />
but when I try this, I get an intellisense error in Visual Studio on that line wanting to change it back to the original line of code.
I'm still getting familiar with jquery, so that skillset isn't that strong yet. I know I'm missing something, but not sure what. If anyone could shed some light on the issue, I'd appreciate it.
I've built a test client page and I'm trying to post to a Web API that I've built, but I get the following error:
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'val'
on the following code:
<!DOCTYPE html>
<html xmlns="http://www.w3/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnSubmit").click(function () {
var user = {
email: ('#txtEmail').val(),
password: ('#txtPassword').val(),
firstName: ('#txtFirstName').val(),
lastName: ('#txtLastName').val(),
country: ('#txtCountry').val(),
postal: ('#txtPostal').val()
};
$.post("http://myUrl/api/****/***************", user, function (data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
I can hit the service in Fiddler with the intended result, so I don't think its my service.
Also, I found a question on Stack talking about a similar issue regarding changing:
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
to
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js" />
but when I try this, I get an intellisense error in Visual Studio on that line wanting to change it back to the original line of code.
I'm still getting familiar with jquery, so that skillset isn't that strong yet. I know I'm missing something, but not sure what. If anyone could shed some light on the issue, I'd appreciate it.
Share Improve this question asked May 15, 2014 at 15:13 Rex_CRex_C 2,4777 gold badges36 silver badges56 bronze badges 2-
1
you're missing the
$
... eg:$('#txtEmail').val(),
etc – Moob Commented May 15, 2014 at 15:14 -
You're missing the
$
from your selectors, eg:email: $('#txtEmail').val()
– Rory McCrossan Commented May 15, 2014 at 15:14
1 Answer
Reset to default 5you are missing $
:
email: $('#txtEmail').val()
it should be like:
var user = {
email: $('#txtEmail').val(),
password: $('#txtPassword').val(),
firstName: $('#txtFirstName').val(),
lastName: $('#txtLastName').val(),
country: $('#txtCountry').val(),
postal: $('#txtPostal').val()
};