无法获取JSON以从Quill文本编辑器将数据发布到ServiceNow API

时间:2019-05-07 14:17:26

标签: javascript json api quil

我需要使用Quill文本编辑器使用JSON将数据发布到API。我可以从API中获取数据,以显示在包含Quill编辑器的模式中,但无法将数据重新发布回API。我不断失败。

我已经尝试了该网站和其他一些脚本。我也尝试了Quill API中的一些脚本。

function showUser(id){
    var updateItems = id.split(',');
    //alert(updateItems[0] + ' ' + updateItems[1] + ' ' + updateItems[2]);
    var sysId = updateItems[0]
    var caller = updateItems[1]
    var incident = updateItems[2]
    var daItems = [sysId + ', ' + caller + ', ' + incident];


const url = "" + sysId + "?sysparm_display_value=true&sysparm_fields=sys_updated_on&sysparm_fields=sys_updated_by%2Cshort_description,%2Ccomments"


$('#prompt').html('Update Incident # ' + incident + '.' + "<br><span class='alert-danger'>Do not use \"QUOTES\". It will cause the submission to fail. </span>" );

    var commentNote = daItems.value //sessionStorage.getItem("enteredComments");    
    var commentNoteFinal = 'Comments posted through API by ' + caller + ': ' + commentNote  
    var settings = {
      "async": true,
      "crossDomain": true,
       //"url": proxyurl + url, //Use this instead to bypass CORS rules
       "url": url,//Comment out if the line above is used
      "method": "PUT",
      "headers": {
        "authorization": "",
        "content-type": "application/json",
        "accept": "application/json",
        //"cache-control": "no-cache",
      },
      "processData": false,
      "data": "{\"comments\":\"" + daItems + "\"}" 

    }

      console.log("Response:");

    if (daItems != null && daItems.length > 1){
        $.ajax(settings).done(function(data) {
        });
    }
}

function submitForm() {

        $('#update').on('submit', function(e){
          $('#myModal2').modal('show');
          e.preventDefault();
        });
    }



I would like this code to submit the post to the API. After hitting the submit button the page reloads. I don't see any errors on the console log. and this is what the URl looks like after I submit: opencallssoapcb.asp?value=

<!-- Modal -->
    <div id="myModal2" class="modal fade2" role="dialog">
      <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">

          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <p id="prompt"></p>
          </div>


              <div class="modal-body">

               <form name="update" id="update">


                <div id="editor-container">
                    <input type="hidden" name="value" value="">
                </div>
                    <!-- Create the editor container -->
                    <div id="editor"></div>
                    <!-- Initialize Quill editor -->
                    <script>

                      var quill = new Quill('#editor', {
                        theme: 'snow',
                        //placeholder: 'Compose an epic...',                        
                      });

                            $("#update").on("submit",function(){
                            $("#hiddenArea").val($("#quillArea").html());
                            })


                    </script>   
              </div>
              <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
                 <button class="btn btn-default btn-primary" type="submit" id="SubmitButton">Submit</button>
              </div>

             </form>

           </div>

      </div>
    </div>

0 个答案:

没有答案