Как отправить данные в формате json в jquery ajax для спокойных веб-сервисовJquery

Программирование на jquery
Ответить
Anonymous
 Как отправить данные в формате json в jquery ajax для спокойных веб-сервисов

Сообщение Anonymous »

Я отправляю данные формата 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»