jQuery的AJAX发布到网络服务 [英] jQuery ajax post to web service

查看:102
本文介绍了jQuery的AJAX发布到网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function() {
        $.ajax({ type: "POST",
                        url: "/getprojects.ashx",
                        data: "<formData client=\"\" year=\"\" categories=\"\" tags=\"\" freeText=\"\" count=\"34\" page=\"1\"></formData>",
                        dataType: "text/xml",
                        cache: false,
                        error: function() { alert("No data found."); },
                        success: function(xml) {
                            alert("it works");
                            alert($(xml).find("project")[0].attr("id"));
                        }
        });
    });

我的问题是,我得到的一些数据回来,但我似乎无法得到它显示出来。

My problem is i get some data back but i can't seem to get it displayed.

推荐答案

的dataType 应该是你能拿到什么类型,但的contentType 应该是MIME类型要发送什么样的,下面应该确定:

dataType should be the type of what you receive but contentType should be the mime-type of what you are sending, the following should be ok:

$(document).ready(function() {
        $.ajax({ type: "POST",
                        url: "/getprojects.ashx",
                        data: "<formData client=\"\" year=\"\" categories=\"\" tags=\"\" freeText=\"\" count=\"34\" page=\"1\"></formData>",
                        contentType: "text/xml",
                        dataType: "xml",
                        cache: false,
                        error: function() { alert("No data found."); },
                        success: function(xml) {
                            alert("it works");
                            alert($(xml).find("project")[0].attr("id"));
                        }
        });
    });

这篇关于jQuery的AJAX发布到网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆