jQuery ajax 发布到 Web 服务 [英] jQuery ajax post to web service

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

问题描述

$(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-type您正在发送,以下内容应该没问题:

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 发布到 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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