2017-10-04 58 views
0

我正在创建一个帐单表单以将数据发送到jsonrpc端点。虽然服务器返回状态码200;我得到这个响应{消息: “解析错误无效的JSON是由服务器接收。”,代码:-32700,..}将表单数据发布到jsponrpc端点时发生-32700错误

$(document).on("submit", "#billing", function(event) 
 
{ 
 
    event.preventDefault();   
 
    $.ajax({ 
 
     url: $(this).attr("action"), 
 
     type: $(this).attr("method"), 
 
     dataType: "JSON", 
 
     data: {new FormData(this)}, 
 
     processData: false, 
 
     contentType: false, 
 
     success: function (data, status) 
 
     { 
 
      console.log('Submission was successful.'); 
 
      console.log(data); 
 
     }, 
 
     error: function (xhr, desc, err) 
 
     { 
 
      console.log('An error occurred.'); 
 
      console.log(data); 
 
     } 
 
    });   
 
});
<form name="billing" id="billing" action="https://XX.XX.XX.XX/ghe/api2/call/jsonrpc2" method="POST"> 
 
    First Name: <input type="text" id="firstname" name="firstname"/> <br/> 
 
    Surname: <input type="text" id="surname" name="surname" /> 
 
<br/> 
 
    Email : <input type="text" id="email" name="email"/> 
 
<br/> 
 
    <input type="submit" name="submit" value="submit"> 
 
</form>

我看到某处字符串化使用,并试图还通过:

$("#submit").click(function() 
 
{ 
 
\t $("#billing").submit(function(e) 
 
\t { 
 
\t \t var postData = $(this).stringify(); 
 
\t \t var formURL = $(this).attr("action"); 
 
\t \t $.ajax(
 
\t \t { 
 
\t \t \t url: $form.attr('action'), 
 
\t \t \t type: "POST", 
 
\t \t \t data : postData, 
 
\t \t \t success:function(data, textStatus, jqXHR) 
 
\t \t \t { 
 
\t \t \t \t console.log("success"); 
 

 
\t \t \t }, 
 
\t \t \t error: function(jqXHR, textStatus, errorThrown) 
 
\t \t \t { 
 
\t \t \t \t console.log("Failed"); 
 
\t \t \t } 
 
\t \t }); 
 
\t }); 
 
\t \t 
 
\t $("#billing").submit(); //SUBMIT FORM 
 
});

但我还是拿到同样的错误资源ponse。我究竟做错了什么?新的API的使用,所以我的知道现在有点分散;希望如果可以指向一个资源URL最适合的API学习..

感谢

回答

0

您需要捕获正在发送到服务器,看看是什么原因造成的无效的Json-RPC异常的有效载荷。你可以console.log(postData)。 或者我建议你的浏览器调试器或fiddler

一旦你捕获了正在发送到服务器的json,你可以把它放在json linter jsonLint.com中,看看是什么导致你的麻烦。

相关问题