weixin_33743703 2009-08-10 21:20 采纳率: 0%
浏览 37

getJSON失败,JSON验证

I have a getJSON call which is inexplicably failing. The idea is, you click to submit a comment, a URL gets hit which determines if the comment is OK or has naughty words in it. The response is given in JSON form.

Here's the paired down JS that generates the call. The comment and the URL are already on the page, it grabs them and hits the URL:

FORM HTML:

<fieldset id="mg_comment_fieldset" class="inlineLabels">
<div class="ctrlHolder">
    <textarea id="id_comment" rows="10" cols="40" name="comment"></textarea>
</div>
<div class="form_block">
    <input type="hidden" name="next" value="" />
    <input id="mg_comment_url" type="hidden" name="comment_url" value="" />

    <input id="mg_comment_submit" type="submit" value="Remark" />
</div>
</fieldset>

SPECIFIC JS BLOCK THAT SENDS/READS RESPONSE:

$('input#mg_comment_submit').click(function(){
var comment = $("textarea#id_comment").val();
var comment_url = $('input#mg_comment_url').val();
$.getJSON(
    comment_url+"?callback=?&comment="+comment+"&next=",
    function(data){
        console.log(data);
        alert(data);
    });         
});

The JSON response:

[{"errors": {"comment": ["Weve detected that your submission contains words which violate our Terms and Conditions. Please remove them and resubmit test"]}}]

It's being returned as a mimetype of application/json. It validates in JSONLint. I also tried adding a couple AJAX functions to try to catch errors, and they're both silent. I can see the request going out in Firebug, and coming back as status 200 responses, which validate in JSONLint and which I can traverse just fine in the JSON tab of the response. If I put an alert before the getJSON, it runs; it's just that nothing inside of it runs. I also find that if I change .getJSON to .get, the alerts do run, suggesting it's something with the JSON. I'm out of ideas as to what the problem could be. Using Firefox 3.0.13.

  • 写回答

4条回答 默认 最新

  • weixin_33739523 2009-08-10 21:34
    关注

    Are you able to manually call your service without any errors? Have you tried using firebug and looked under XBR to see the post/response of the JSON payloads? I normally use .NET as my endpoints, and with .NET 3.5 I need to use content type "application/json; charset=utf-8".

    Here is an example of a working JSON call I use in .NET with jQuery 1.3.2

    $.ajax({   
        type: "POST",   
        url: "WebService1.ASMX/HelloWorld",   
        contentType: "application/json; charset=utf-8",   
        dataType: "json",   
        data: "{}",   
        success: function(res) {   
        // Do your work here.   
        // Remember, the results for a ASMX Web Service are wrapped   
        // within the object "d" by default. e.g. {"d" : "Hello World"}   
        }   
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?