• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    AJAX 异步传输数据的问题
    要异步传输的数据:
    Xml代码
    ....
    action xsi:type="basic:JavaScript" script="index += 1;"/>
    ....
    Ajax异步传输代码:
    Js代码
    复制代码 代码如下:

    var postData = "input="+ escape(inputJSON) +"script="+escape(xml)+
    "feedGeneral=" + escape(feedGeneral);
    XmlHttpRequest.open("POST",url,true);
    XmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    XmlHttpRequest.send(postData);

    postData在encode和unencode,最终导致在后台Servlet中得到得到数据+被空格代替,使得script中的index += 1;变成了index = 1;从而导致后台Java代码在跑script出现死循环。
    在网上搜索,发现content-type使用application/x-www-form-urlencoded后:
    [来自http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1]写道
    复制代码 代码如下:

    Control names and values are escaped. Space characters are replaced by `+', and then reserved characters are escaped as
    described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal
    digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').

    然而使用form来提交方式来发起request却不会出现类似的问题,而form默认的Content-Type也是application/x-www-form-urlencoded:
    Js代码
    复制代码 代码如下:

    $('test').innerHTML = "form target='_blank' id='test_form' action='./gen_feed' method='post'>"
    + "input type='text' name='input' />input type='text' name='script' />"
    + "input type='text' name='feedGeneral' />input type='hidden' name='format' value='" + this.feed_type + "'
    />"
    + "input type='submit' value='gen' />/form>";
    var test_form = $('test_form');
    test_form.elements[0].value = inputJSON;
    test_form.elements[1].value = script;
    test_form.elements[2].value = feedGeneral;
    test_form.submit();

    仍未发现问题到底出在何处,暂做备忘。暂时把script中的‘+'都用‘-'代替,index += 1;改成index -= -1;呵呵,以后有人看到这段自动生成的诡异脚本,不知道会作何感想,但现在也只能如此。
    您可能感兴趣的文章:
    • ajax.js里面有内容显示效果,根据ID
    • asp.net下 jquery jason 高效传输数据
    • 基于Jquery的跨域传输数据(JSONP)
    • JavaScript使表单中的内容显示在屏幕上的方法
    • JS实现左右拖动改变内容显示区域大小的方法
    • java编程实现基于UDP协议传输数据的方法
    • Python爬虫抓取手机APP的传输数据
    • js实现内容显示并使用json传输数据
    上一篇:Ajax+PHP简单基础入门实例教程
    下一篇:ASP AJAX 静态分页第1/2页
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    AJAX 异步传输数据的问题 AJAX,异步,传输,数据,的,