0
有人能幫助我。這總是出錯,但沒有錯誤信息,只是console.log。有沒有什麼好的方法來調試,或者你只是看到這個有什麼問題?發佈數據不能正常工作
謝謝! 薩米
function foo(){
alert('Button pressed');
var user={"id":10,"firstName":" Ted","lastName":"TESTING","age":69,"freeText":"55555","weight":55};
$.ajax({
type: "POST",
contentType: "application/json",
url: "http://localhost:8080/testSoft/webresources/entity.user/",
dataType: "json",
data: user,
success: function(data){alert(data);},
error: function(data) {
console.log('#####################error:################################'+data);
alert('addUser error: ' + data.firstName);
}
});
};
Web服務:
@POST
@Override
@Consumes({"application/xml", "application/json"})
public void create(User entity) {
super.create(entity);
}
用戶
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Size(max = 45)
@Column(name = "firstName")
private String firstName;
@Size(max = 45)
@Column(name = "lastName")
private String lastName;
@Column(name = "age")
private Integer age;
@Lob
@Size(max = 65535)
@Column(name = "freeText")
private String freeText;
@Column(name = "weight")
private Integer weight;
那麼,是什麼「只是執行console.log」告訴你嗎?難道請求到達您的服務器端應用程序嗎?你嘗試調試呢? – home 2013-02-11 17:46:10
####### ##############錯誤:################################ [對象對象](19:50:22:273)alert('addUser error:'+ data.firstName);說錯誤:und efiened。什麼是調試javaScritp + webservices的最佳工具? – Sami 2013-02-11 17:53:02
你有沒有在你的控制器操作中設置一個斷點來驗證它甚至被調用?另外,通常我看到網址,在「.something」結尾,表示客戶端請求數據的類型,是「用戶」你想實現一個自定義格式? – BrMcMullin 2013-02-11 18:06:05