.net jquery ajax應用(前端)

來源:互聯網
上載者:User

標籤:

 //一般處理常式,GET方式提交(data:要傳送的資料索引值對)     
            jQuery.ajax(
                                                { type: ‘GET‘,
                                                    url: ‘GradeHandler.ashx?startCount&starDescri‘,
                                                    data: { startCount: startCount, starDescri: starDescri },                  //(對)
                                                    // data: ‘{ startCount:"‘ + startCount + ‘",starDescri:"‘ + starDescri + ‘"}‘, (錯)             
                                                    contentType: "application/json; charset=utf-8",
                                                    dataType: ‘json‘,
                                                    success: function (result) {
                                                        if (result)//返回true
                                                            alert(‘評分成功!‘);
                                                        else
                                                            alert(‘評分失敗‘ + result);
                                                    },
                                                    error: function () {
                                                        alert("ajax調用錯誤");
                                                    }
                                                }
                                                    );

   //一般處理常式,POST方式提交(data:要傳送的資料索引值對)
            jQuery.ajax(
                                { type: ‘POST‘,
                                    url: ‘GradeHandler.ashx‘,
                                    data: { startCount: startCount, starDescri: starDescri },      //(對)
                                    //  data: ‘{ startCount:"‘ + startCount + ‘",starDescri:"‘ + starDescri + ‘"}‘,  //(錯)
                                    //  contentType: "application/json; charset=utf-8",            //不能添加該參數
                                    dataType: ‘json‘,
                                    success: function (result) {
                                        if (result)//返回true
                                            alert(‘評分成功!‘);
                                        else
                                            alert(‘評分失敗‘ + result);
                                    },
                                    error: function () {
                                        alert("ajax調用錯誤");
                                    }
                                }
                                    );

           /*
            jQuery調用WebService的方法(只能發送post方式的請求);
            返回json格式的資料時,需設定contentType為application/json (data要用Json的字串格式傳入)
            返回的資料是以字母d為索引值的json對象。
            */
            jQuery.ajax(
                                            { type: ‘POST‘,
                                                url: ‘WebService/GradeWebService.asmx/UserGrade‘,
                                                data: ‘{ count:"‘ + startCount + ‘",descri:"‘ + starDescri + ‘"}‘,     //(對)
                                                // data: { count: startCount, descri: starDescri },                        //(錯)       
                                                contentType: "application/json; charset=utf-8",
                                                dataType: ‘json‘,
                                                success: function (result) {
                                                    if (result.d)//返回true
                                                        alert(‘評分成功!‘ + result.d);
                                                    else
                                                        alert(‘評分失敗‘ + result.d);
                                                },
                                                error: function () {
                                                    alert("ajax調用錯誤");
                                                }
                                            }
                                                );

 

.net jquery ajax應用(前端)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.