Я отправляю данные формата json в jquery ajax для спокойных веб-сервисов, но они не отправляются. Я новичок в веб-технологиях, поэтому, пожалуйста, помогите мне. Я пишу сценарий для отправки данных JSON, используя следующую ссылку
как передать данные JSON в веб-сервисы через ajax, а также как получить данные JSON?
Мой код JavaScript
$(document).ready(function(){
$('#btnBooking').click(function(){
var serviceCategory=document.getElementById("services").value;
var availDate=document.getElementById("scheduledDate").value;
var custName=document.getElementById("userName").value;
var custMobile=document.getElementById("userContactNumber").value;
var custEmail=document.getElementById("addressemailId").value;
var custAddress=document.getElementById("address1").value;
var JSONObject= {"serviceCategory":serviceCategory, "availDate":availDate, "custName":custName, "custMobile":custMobile, "custEmail":custEmail, "custAddress":custAddress};
var jsonData = JSON.stringify( JSONObject );
$.ajax({
url: "http://localhost:8080/HomeServiceProvid ... ingDetails",
type: "POST",
dataType: "json",
data: jsonData,
contentType: "application/json",
success: function(response){
alert(JSON.stringify(response));
},
error: function(err){
alert(JSON.stringify(err));
}
});
});
});
Мой HTML-код
Error
Message Goes Here
Name:*
Services:
Select Service
Carpenter
Mobile SIM services
Schedule Date:*
Address:*
City:
Mobile:*
Email:*
Confirm Booking
Booking.java
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Booking generated by hbm2java
*/
@Entity
@Table(name = "booking", catalog = "service4homes")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Booking implements java.io.Serializable {
private Integer BId;
private ServiceProviderStatus serviceProviderStatus;
private ServiceCategory serviceCategory;
private Date availDate;
private String custName;
private String custMobile;
private String custEmail;
private String custAddress;
private Set allocations = new HashSet(0);
private Set superAdmins = new HashSet(0);
public Booking() {
}
public Booking(ServiceProviderStatus serviceProviderStatus,
Customer customer, ServiceCategory serviceCategory, Date availDate,
String custEmail) {
this.serviceProviderStatus = serviceProviderStatus;
this.serviceCategory = serviceCategory;
this.availDate = availDate;
this.custEmail = custEmail;
}
public Booking(ServiceProviderStatus serviceProviderStatus,
Customer customer, ServiceCategory serviceCategory, Date availDate,
String custName, String custMobile, String custEmail,
String custAddress, Set allocations,
Set superAdmins) {
this.serviceProviderStatus = serviceProviderStatus;
this.serviceCategory = serviceCategory;
this.availDate = availDate;
this.custName = custName;
this.custMobile = custMobile;
this.custEmail = custEmail;
this.custAddress = custAddress;
this.allocations = allocations;
this.superAdmins = superAdmins;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "b_id", unique = true, nullable = false)
public Integer getBId() {
return this.BId;
}
public void setBId(Integer BId) {
this.BId = BId;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "sps_id", nullable = false)
@JsonIgnore
public ServiceProviderStatus getServiceProviderStatus() {
return this.serviceProviderStatus;
}
public void setServiceProviderStatus(
ServiceProviderStatus serviceProviderStatus) {
this.serviceProviderStatus = serviceProviderStatus;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "sc_id", nullable = false)
@JsonIgnore
public ServiceCategory getServiceCategory() {
return this.serviceCategory;
}
public void setServiceCategory(ServiceCategory serviceCategory) {
this.serviceCategory = serviceCategory;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "avail_date", nullable = false, length = 19)
public Date getAvailDate() {
return this.availDate;
}
public void setAvailDate(Date availDate) {
this.availDate = availDate;
}
@Column(name = "cust_name", length = 50)
public String getCustName() {
return this.custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
@Column(name = "cust_mobile", length = 13)
public String getCustMobile() {
return this.custMobile;
}
public void setCustMobile(String custMobile) {
this.custMobile = custMobile;
}
@Column(name = "cust_email", nullable = false, length = 50)
public String getCustEmail() {
return this.custEmail;
}
public void setCustEmail(String custEmail) {
this.custEmail = custEmail;
}
@Column(name = "cust_address", length = 100)
public String getCustAddress() {
return this.custAddress;
}
public void setCustAddress(String custAddress) {
this.custAddress = custAddress;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "booking")
public Set getAllocations() {
return this.allocations;
}
public void setAllocations(Set allocations) {
this.allocations = allocations;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "booking")
@JsonIgnore
public Set getSuperAdmins() {
return this.superAdmins;
}
public void setSuperAdmins(Set superAdmins) {
this.superAdmins = superAdmins;
}
}
Подробнее здесь: https://stackoverflow.com/questions/280 ... b-services
Как отправить данные в формате json в jquery ajax для спокойных веб-сервисов ⇐ Jquery
Программирование на jquery
1715569555
Anonymous
Я отправляю данные формата json в jquery ajax для спокойных веб-сервисов, но они не отправляются. Я новичок в веб-технологиях, поэтому, пожалуйста, помогите мне. Я пишу сценарий для отправки данных JSON, используя следующую ссылку
как передать данные JSON в веб-сервисы через ajax, а также как получить данные JSON?
[b]Мой код JavaScript[/b]
$(document).ready(function(){
$('#btnBooking').click(function(){
var serviceCategory=document.getElementById("services").value;
var availDate=document.getElementById("scheduledDate").value;
var custName=document.getElementById("userName").value;
var custMobile=document.getElementById("userContactNumber").value;
var custEmail=document.getElementById("addressemailId").value;
var custAddress=document.getElementById("address1").value;
var JSONObject= {"serviceCategory":serviceCategory, "availDate":availDate, "custName":custName, "custMobile":custMobile, "custEmail":custEmail, "custAddress":custAddress};
var jsonData = JSON.stringify( JSONObject );
$.ajax({
url: "http://localhost:8080/HomeServiceProvider/rest/booking/saveBookingDetails",
type: "POST",
dataType: "json",
data: jsonData,
contentType: "application/json",
success: function(response){
alert(JSON.stringify(response));
},
error: function(err){
alert(JSON.stringify(err));
}
});
});
});
[b]Мой HTML-код[/b]
Error
Message Goes Here
Name:*
Services:
Select Service
Carpenter
Mobile SIM services
Schedule Date:*
Address:*
City:
Mobile:*
Email:*
[url=index.html]Confirm Booking [/url]
[b]Booking.java[/b]
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Booking generated by hbm2java
*/
@Entity
@Table(name = "booking", catalog = "service4homes")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Booking implements java.io.Serializable {
private Integer BId;
private ServiceProviderStatus serviceProviderStatus;
private ServiceCategory serviceCategory;
private Date availDate;
private String custName;
private String custMobile;
private String custEmail;
private String custAddress;
private Set allocations = new HashSet(0);
private Set superAdmins = new HashSet(0);
public Booking() {
}
public Booking(ServiceProviderStatus serviceProviderStatus,
Customer customer, ServiceCategory serviceCategory, Date availDate,
String custEmail) {
this.serviceProviderStatus = serviceProviderStatus;
this.serviceCategory = serviceCategory;
this.availDate = availDate;
this.custEmail = custEmail;
}
public Booking(ServiceProviderStatus serviceProviderStatus,
Customer customer, ServiceCategory serviceCategory, Date availDate,
String custName, String custMobile, String custEmail,
String custAddress, Set allocations,
Set superAdmins) {
this.serviceProviderStatus = serviceProviderStatus;
this.serviceCategory = serviceCategory;
this.availDate = availDate;
this.custName = custName;
this.custMobile = custMobile;
this.custEmail = custEmail;
this.custAddress = custAddress;
this.allocations = allocations;
this.superAdmins = superAdmins;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "b_id", unique = true, nullable = false)
public Integer getBId() {
return this.BId;
}
public void setBId(Integer BId) {
this.BId = BId;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "sps_id", nullable = false)
@JsonIgnore
public ServiceProviderStatus getServiceProviderStatus() {
return this.serviceProviderStatus;
}
public void setServiceProviderStatus(
ServiceProviderStatus serviceProviderStatus) {
this.serviceProviderStatus = serviceProviderStatus;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "sc_id", nullable = false)
@JsonIgnore
public ServiceCategory getServiceCategory() {
return this.serviceCategory;
}
public void setServiceCategory(ServiceCategory serviceCategory) {
this.serviceCategory = serviceCategory;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "avail_date", nullable = false, length = 19)
public Date getAvailDate() {
return this.availDate;
}
public void setAvailDate(Date availDate) {
this.availDate = availDate;
}
@Column(name = "cust_name", length = 50)
public String getCustName() {
return this.custName;
}
public void setCustName(String custName) {
this.custName = custName;
}
@Column(name = "cust_mobile", length = 13)
public String getCustMobile() {
return this.custMobile;
}
public void setCustMobile(String custMobile) {
this.custMobile = custMobile;
}
@Column(name = "cust_email", nullable = false, length = 50)
public String getCustEmail() {
return this.custEmail;
}
public void setCustEmail(String custEmail) {
this.custEmail = custEmail;
}
@Column(name = "cust_address", length = 100)
public String getCustAddress() {
return this.custAddress;
}
public void setCustAddress(String custAddress) {
this.custAddress = custAddress;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "booking")
public Set getAllocations() {
return this.allocations;
}
public void setAllocations(Set allocations) {
this.allocations = allocations;
}
@OneToMany(fetch = FetchType.EAGER, mappedBy = "booking")
@JsonIgnore
public Set getSuperAdmins() {
return this.superAdmins;
}
public void setSuperAdmins(Set superAdmins) {
this.superAdmins = superAdmins;
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/28010440/how-to-send-data-in-json-format-in-jquery-ajax-for-restfull-web-services[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия