사용하고있는 ajax 요청을 통해 컨트롤러에 데이터를 전송하는 데 문제가 있습니다.Ajax를 통해 컨트롤러에 텍스트 보내기
내보기에 현재, 나는
<p>Please enter your email and phone number registered with the account</p>
<table id="Table">
<tr>
<td>Email</td>
<td> <input id = "email" type ="text" name= "email" /></td>
</tr>
<tr>
<td>Phone Number</td>
<td> <input id = "phone" type ="text" name= "phone" /></td>
</tr>
</table>
<input type="button" value="Submit" id="sendMSG">
나는이 함수를 호출 할 때
<script src="http://code.jquery.com/jquery-1.9.1.js">
</script>
<script>
$("#sendMSG").click(function() {
$.ajax({
type: "POST",
url: '@Url.Action("SendMessage", "SMSTest")',
dataType: "JSon",
data: { "email": $("#email").toString(), "phone": $("#phone").toString()},
success: function (data) {
console.log(data);
},
error: console.log("it did not work"),
});
});
</script>
, 내 SMSTestController
public JsonResult SendMessage(string email, string phone)
{}
로 전송 다음 스크립트를 가지고있는 I 현재 전자 메일과 전화로받을 값은 [object Object]
이며 유형은 st입니다. 버튼을 클릭 한 후 내 이메일과 전화 모두에 전화를 겁니다.
내가 입력 한 실제 문자열을 컨트롤러에 직접 입력하는 방법에 대한 아이디어가 있습니까? 당신은 입력 필드의 값을 잡는되지 않습니다
<script>
$("#sendMSG").click(function() {
$.ajax({
type: "POST",
url: '@Url.Action("SendMessage", "SMSTest")',
dataType: "JSon",
data: { "email": $("#email").val(), "phone": $("#phone").val()},
success: function (data) {
console.log(data);
},
error: console.log("it did not work"),
});
});
</script>
입력 값을 얻으려면, 당신이 작성해야합니다 : ($ ("# 메일") 발을). –
@ Joffrey Kem 고마워요! 감사합니다 : D – user2094139
환영합니다 :) –