0

フォーム付きの 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({
       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);
}

今私が欲しいのは、同じシステム上にあるサーバーとクライアントの間で通信することです。コードが機能しません。今、私は何ができますか、助けてください。

4

2 に答える 2

1

まず、サーバーがポート 8080 (通常は管理ソフトウェア用のポート) をリッスンしているとは思いません。

2番目に、ajaxリクエスト内にURLを配置する必要があります

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);
}

dataTypeパラメータリストに(htmlまたはjson)、送信type(post、getなど)も追加する必要があります

于 2013-01-21T10:52:20.830 に答える
1

ツアーコードを少し変更すると役立つかもしれません:

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");
    });
}
于 2013-01-21T10:53:04.573 に答える