Javascript 服务器和客户端在同一系统上时如何捕获JSON对象
我制作了具有表单的HTML页面,提交时,它使用此事件处理程序调用JavaScriptJavascript 服务器和客户端在同一系统上时如何捕获JSON对象,javascript,jquery,html,ajax,json,Javascript,Jquery,Html,Ajax,Json,我制作了具有表单的HTML页面,提交时,它使用此事件处理程序调用JavaScript onClick = operation(this.form) JavaScript是: function operation(x) { //url:"C:\Users\jhamb\Desktop\assignment_1_18_1_13\question_3\ques\form1.html", url:"http://localhost:8080", $.ajax({
onClick = operation(this.form)
JavaScript是:
function operation(x) {
//url:"C:\Users\jhamb\Desktop\assignment_1_18_1_13\question_3\ques\form1.html",
url:"http://localhost:8080",
$.ajax({
data:{
comment:x.comment.value, // information from html page
email: x.email.value, // information from html page
url:x.url.value, // information from html page
name:x.name.value, // information from html page
}
}).done(function(serverResponse){
alert("response is ready"); //here you can handle server response
}).fail(function(err){
alert("ohhh!!! there is some error"); //here you can handle errors
});
//alert(obj.details[3].comment_value);
}
现在我想要的是在同一个系统上的服务器和客户端之间进行通信。
我的代码不起作用。现在我能做什么,请帮助。首先,我认为您的服务器不会监听端口8080,这是管理软件的正常端口 其次,必须将url放入ajax请求中
function operation(x) {
//url:"C:\Users\jhamb\Desktop\assignment_1_18_1_13\question_3\ques\form1.html",
$.ajax({
url:"http://localhost:8080",
data:{
comment:x.comment.value, // information from html page
email: x.email.value, // information from html page
url:x.url.value, // information from html page
name:x.name.value, // information from html page
}
}).done(function(serverResponse){
alert("response is ready"); //here you can handle server response
}).fail(function(err){
alert("ohhh!!! there is some error"); //here you can handle errors
});
//alert(obj.details[3].comment_value);
}
您还应在参数列表中添加
数据类型
(html或json),发送类型
(post、get等)如果您稍微修改巡更代码,可能会有所帮助:
function operation(x) {
$.ajax({
url: "http://localhost:8080",
data: $(x).serialize(),
}).done(function (serverResponse) {
alert("response is ready");
}).fail(function (err) {
alert("ohhh!!! there is some error");
});
}
您是否在主机中设置了一个web服务器,它是否在端口8080中侦听?可能是一个输入错误,但它是否符合我注意到的onClick=opeation(this.form)的方法。现在我只写了这些代码。除此之外,我什么都不知道。(因为我是这项技术的新手)重新检查一下你的函数名,就像@CR41G14所说的,可能这就是问题所在:D