You are viewing limited content. For full access, please sign in.

Question

Question

ajax call using #form1

asked on November 30, 2017 Show version history

Good afternoon,

Prior to Forms 10.2.1 we were using the code as below, but with the line var frm = $("#form1") activated and the other one below it did not exist.

When we migrated to 10.2.1 it now would fail if we used #form1, so in doing trail and error I found out that doing "document" works, but wanted to check with you if you know why this would happen. 

In viewing the source code we found that there there is no "form" tag or "#form1" id, so I decided to give "document" a try, which worked for the little snippet below.

Anyone having to do similar updates in order to make an ajax call snippet work. If you have any links to documentation I'd  appreciate if you could share it, so that I can take a closer look at what I should be using. 

If we use "#form1" I get the error: error on submit An unexpected error has occurred. [LFF502-UnexpectedError]

$(document).ready(function() {

  FormSubmit();
  
});

function FormSubmit() {
    //var frm = $("#form1");  // no longer works
    var frm = $(document);  // this is new and works for the little test

      $.ajax({
        url: frm.attr("action"),
        data: frm.serialize(),       
        type: "post",  
        success: function (data) {
          
          var obj = jQuery.parseJSON( '{ "name": "test" }' );
		  var r = (obj.name === "test" );
          alert('success on submit ' + r);        
        },
        error: function (data) {
           var r = jQuery.parseJSON(data.responseText);
           alert('error on submit ' + r.message);            
        }
    });

}

 

0 0

Answer

SELECTED ANSWER
replied on December 7, 2017

Hi Raul,

I tried on Forms 10.2.1, but the $("#form1") still exists on form:

There will be error when use $("#form1") in your script. It is because in Forms 10.2.1 it will check the action for submission. So you need to add "&action=Submit" in form data (Submit is the action button) like this:

data: frm.serialize() + "&action=Submit",

And when I use $(document), although it alerts success but the form is not submitted. 

0 0
replied on December 7, 2017

Rui Thanks,

Setting it up like the example you provided does work for our test code. We'll try it on the actual production code and hopefully this tweak fixes the issues that we are encountering.

Thanks again,

Raul Gonzalez

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.