Jquery ajax调用将数据传递给服务器 [英] Jquery ajax calling passing data to server
问题描述
在下面的代码中我尝试从文本框发送值到服务器在线存在的方法,但它警告错误 in the following code i try to send values from textboxs to method exist in server on line but it alert error 这篇关于Jquery ajax调用将数据传递给服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
< pre lang =JavaScript> // /< reference path =jquery-1.8.2.min.js />
$( document )。ready( function (){
$( #btnRegister)。click( function (){
if ($( #txtFirstname)。val()== 0 || $( #txtNickname)。val()== 0 || $( #txtGmail)。val()== 0 || $( #txtPassword)。val()== 0 || $( #txtBirth)。val()== 0 ){
alert( 数据空)
}
else {
Register();
}
});
function 注册(){
var IsMale = 1 ;
var name = $( #txtFirstname 跨度>)VAL();
var nickName = $( #txtNickname 跨度>)VAL();
var email = $( #txtGmail 跨度>)VAL();
var 密码= $( #txtPassword 跨度>)VAL();
var birthDate = $( #txtBirth 跨度>)VAL();
$ .ajax({
type: GET ,
contentType: application / json; charset = utf-8 ,
url: http://lashteam-001-site1.btempurl.com/app/user/注册/ + IsMale + / + name + / + nickName + / + email + / + password + / + birthDate,
// url:http:// localhost:3148 / api / values / 5,
成功: function (data){
alert(data);
var obj = jQuery.parseJSON(data);
alert( ID = + obj.longPachage.Id);
alert( Success 2);
},
错误: function (数据){
alert( 错误);
}
})
}
});
我尝试了什么:
i尝试在本地主机警报成功,但我想在服务器上进行
如果我使用此链接作为测试
http://lashteam-001-site1.btempurl.com/app/user/Registering/1/osama/os/osama@yahoo.com/123 / 2010-02-25
它工作但我希望它接受来自文本框的值( document )。ready( function (){
( #btnRegister)。点击( function (){
(
< span class =code-keyword> if
( #txtFirstname)。val()== 0 ||
/// <reference path="jquery-1.8.2.min.js" />
$(document).ready(function () {
$("#btnRegister").click(function () {
if ($("#txtFirstname").val() == 0 || $("#txtNickname").val() == 0 || $("#txtGmail").val() == 0 || $("#txtPassword").val() == 0 || $("#txtBirth").val() == 0) {
alert("Data Empty")
}
else {
Register();
}
});
function Register() {
var IsMale = 1;
var name = $("#txtFirstname").val();
var nickName = $("#txtNickname").val();
var email = $("#txtGmail").val();
var password = $("#txtPassword").val();
var birthDate = $("#txtBirth").val();
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://lashteam-001-site1.btempurl.com/app/user/Registering/" + IsMale + "/" + name + "/" + nickName + "/" + email + "/" + password + "/" + birthDate,
// url: "http://localhost:3148/api/values/5",
success: function (data) {
alert(data);
var obj = jQuery.parseJSON(data);
alert("ID ="+obj.longPachage.Id);
alert("Success 2");
},
error: function (data) {
alert(" Error ");
}
})
}
});
What I have tried:
i try it on local host alert success but i want do in on the server
if i use this link as a test
http://lashteam-001-site1.btempurl.com/app/user/Registering/1/osama/os/osama@yahoo.com/123/2010-02-25
it work but i want it accept values from textboxs(document).ready(function () {
("#btnRegister").click(function () {
if (
("#txtFirstname").val() == 0 ||