Ajax网址未定义

时间:2018-10-25 08:40:12

标签: javascript jquery ajax

我正在创建一个函数来获取xml文件并对其进行编辑。我之前从未做过,所以我搜索了一种获取xml文件的好方法。我决定使用ajax,但由于未定义url,因此从未返回文件。

编辑: 我编辑了代码,并在成功函数中进行了处理。现在此文件没有问题。 这是ajax部分的更新:

$.ajax({
    type: 'GET',
    url: 'allrtp.xml',
    dataType: 'xml',
    success: function(xml) {
        //file = $.parseXML(xml);

        // Editing the file to have the good dates
        $(xml).find('StartDateTime').text(start);
        $(xml).find('EndDateTime').text(end);

        var strFile;

        if (window.ActiveXObject) {
            strFile = xml.xml;
        } else {
            strFile = (new XMLSerializer()).serializeToString(xml);
        }

        var encoded64 = Base64.encode(strFile); // Encoded in base64
        var encodeURL = encodeURIComponent(encoded64); // Encoded URL

        var AR = urlAR + encodeURL; // The URL to open
        window.open(AR, '_blank');
    }
})

现在,关于xml文件的一切工作都很好,我的window.open有一个小问题,它打开了我的网址,但开头是%31,但这是另一个问题。

谢谢您的帮助!

3 个答案:

答案 0 :(得分:0)

添加错误回调:   错误:函数(例如){}

许多事情都可能发生,您将通过错误回调获得更多信息。可能是您查询的网址不正确。不要相信未定义的url,请参阅返回您的jquery ajax函数的内容。也许您应该查询“ \ files \ xxx.xml”之类的东西。

答案 1 :(得分:0)

文件未定义,因为您在ajax成功函数中声明了文件

FROM alpine:latest

ARG DPDK_VER=16.11.8
ARG KERNEL_VER=4.9.4

RUN wget https://git.dpdk.org/dpdk-stable/snapshot/dpdk-stable-$DPDK_VER.tar.gz && \
    tar -xzf dpdk-stable-$DPDK_VER.tar.gz && \
    \
    # Install Alpine packages
    apk add --no-cache make gcc linux-headers bsd-compat-headers binutils coreutils diffutils && \
    apk add --no-cache gettext bash grep sed texinfo perl util-linux vim build-base libexecinfo libexecinfo-dev && \
    apk add --no-cache abuild bc cmake ncurses-dev ca-certificates wget && \
    apk add numactl-dev --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted && \
    \
    # Enable usage of High Precision Timers
    sed -i "/\b\(CONFIG_RTE_LIBEAL_USE_HPET\|n\)\b/d" /dpdk-stable-$DPDK_VERSION/config/common_base && \
    sed -ie '/CONFIG_RTE_LOG_HISTORY=256/a CONFIG_RTE_LIBEAL_USE_HPET=y' /dpdk-stable-$DPDK_VERSION/config/common_base && \
    \
    # Add following lines / workarounds to header files 
    sed -ie '/int cmsg_type;/a unsigned char __cmsg_data;' /usr/include/bits/socket.h && \
    sed -i.old '1s;^;#include <fcntl.h>\n;' /dpdk-stable-$DPDK_VER/lib/librte_eal/common/include/rte_common.h && \
    sed -ie '/#define _VNIC_DEVCMD_H_/a typedef u32 u_int32_t;' /dpdk-stable-$DPDK_VER/drivers/net/enic/base/vnic_devcmd.h && \
    \
    # Prevent usage of the header files on /usr/include/fortify path by deleting them
    # Instead of them header files from /usr/include path will be used
    rm -rf /usr/include/fortify/* && \
    \
    # Add CFLAGS += -D_GNU_SOURCE to the following Makefiles
    cd /dpdk-stable-$DPDK_VER && \
    sed -ie '/CFLAGS/a CFLAGS += -D_GNU_SOURCE' lib/librte_ring/Makefile && \
    sed -ie '/CFLAGS/a CFLAGS += -D_GNU_SOURCE' lib/librte_mempool/Makefile && \
    sed -ie '/CFLAGS/a CFLAGS += -D_GNU_SOURCE' lib/librte_mbuf/Makefile && \
    sed -ie '/CFLAGS/a CFLAGS += -D_GNU_SOURCE' lib/librte_timer/Makefile && \
    sed -ie '/CFLAGS/a CFLAGS += -D_GNU_SOURCE' lib/librte_net/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_eal/linuxapp/eal/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_ether/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_cryptodev/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_vhost/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_hash/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_lpm/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_acl/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_ip_frag/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_sched/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_distributor/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_kni/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_port/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_table/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_pipeline/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' lib/librte_reorder/Makefile && \
    \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/af_packet/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/bonding/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/cxgbe/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/e1000/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/ena/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/enic/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/fm10k/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/i40e/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/ixgbe/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/bnxt/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/null/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/qede/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/ring/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/virtio/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/vmxnet3/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/net/vhost/Makefile && \
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' drivers/crypto/null/Makefile && \
    \
    # Enable tests for compiling
    sed -ie '/EXECENV_LDLIBS  += -ldl/a EXECENV_LDLIBS  += -lexecinfo' mk/exec-env/linuxapp/rte.vars.mk && \
    sed -ie '/#include <string.h>/a #include <features.h>' lib/librte_eal/linuxapp/eal/eal_pci_uio.c && \
    sed -ie '/#define OFF_MAX/a static inline void outb_p (unsigned char __value, unsigned short int __port) { __asm__ __volatile__ ("outb %b0,%w1\\noutb %%al,$0x80": :"a" (__value), "Nd" (__port)); }' lib/librte_eal/linuxapp/eal/eal_pci_uio.c && \
    sed -ie '/#define OFF_MAX/a static inline void outw_p (unsigned short int __value, unsigned short int __port) { __asm__ __volatile__ ("outw %w0,%w1\\noutb %%al,$0x80": :"a" (__value), "Nd" (__port)); }' lib/librte_eal/linuxapp/eal/eal_pci_uio.c && \
    sed -ie '/#define OFF_MAX/a static inline void outl_p (unsigned int __value, unsigned short int __port) { __asm__ __volatile__ ("outl %0,%w1\\noutb %%al,$0x80": :"a" (__value), "Nd" (__port)); }' lib/librte_eal/linuxapp/eal/eal_pci_uio.c && \
    # - test
    sed -ie '/LDLIBS += -lm/a LDLIBS += -lrte_pmd_ring -lrte_pmd_null' app/test/Makefile && \
    # - test-acl
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' app/test-acl/Makefile && \
    # - test-pipeline
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' app/test-pipeline/Makefile && \
    # - test-pmd
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' app/test-pmd/Makefile && \
    sed -ie '/DEPDIRS-y += lib drivers/a LDLIBS += -lrte_pmd_ixgbe' app/test-pmd/Makefile && \
    sed -ie '/typedef uint16_t streamid_t/a typedef unsigned int uint;' app/test-pmd/testpmd.h && \
    # - proc_info
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' app/proc_info/Makefile && \
    # - pdump
    sed -ie '/CFLAGS += $(WERROR_FLAGS)/a CFLAGS += -D_GNU_SOURCE' app/pdump/Makefile && \
    cd / && \
    \
    # Install missing Alpine Linux kernel modules
    wget -nv -P /srv https://www.kernel.org/pub/linux/kernel/v4.x/linux-$KERNEL_VER.tar.gz && \
    tar -C /srv -zxf /srv/linux-$KERNEL_VER.tar.gz && \
    cd /srv/linux-$KERNEL_VER && \
    make defconfig && \
    ([ ! -f /proc/1/root/proc/config.gz ] || zcat /proc/1/root/proc/config.gz > .config) && \
    echo 'CONFIG_USB=m' >> .config && \
    echo 'CONFIG_USB_HID=m' >> .config && \
    echo 'CONFIG_USB_SUPPORT=y' >> .config && \
    echo 'CONFIG_USB_COMMON=m' >> .config && \
    echo 'CONFIG_USB_ARCH_HAS_HCD=y' >> .config && \
    echo 'CONFIG_USB_DEFAULT_PERSIST=y' >> .config && \
    echo 'CONFIG_USBIP_CORE=m' >> .config && \
    echo 'CONFIG_USBIP_VHCI_HCD=m' >> .config && \
    echo 'CONFIG_USBIP_VHCI_HC_PORTS=8' >> .config && \
    echo 'CONFIG_USBIP_VHCI_NR_HCS=1' >> .config && \
    echo 'CONFIG_USBIP_HOST=m' >> .config && \
    sed -i'.bak' '/hcd->amd_resume_bug/{s/^/\/\//;n;s/^/\/\//}' ./drivers/usb/core/hcd-pci.c && \
    make oldconfig && \
    make modules_prepare && \
    make modules && \
    make modules_install && \
    make clean && \
    cd / && \
    \
    # Install DPDK
    mkdir /dpdk-build && \
    cd dpdk-stable-$DPDK_VER && \
    make install T=x86_64-native-linuxapp-gcc RTE_KERNELDIR=/srv/linux-$KERNEL_VER DESTDIR=/dpdk-build

答案 2 :(得分:-1)

您能给我一张浏览器中网络的照片吗?我想知道URL是否发送:   1. F12打开控制台   2.选择网络选项卡   3.刷新浏览器   4.检查请求是否发送