2

I've placed a form on a page that I must use ajax to submit with. Since I'm using a .net site I can't place the form tag around the form and I don't have access to the backend (nor the knowledge of .net)

My solution is to set the form tag to a div and use data- to get the action and method attributes. I'm doing a preventDefault on the button and attempting to use AJAX to submit my form:

$('.js-submit').on('click',function(e){
    e.preventDefault();
    var thisForm = $(this).closest('.contentForm');
    var formAction = thisForm.attr('data-action');
    var formMethod = thisForm.attr('data-method');

    var data = thisForm.find("input,select,textarea").serialize()

    $.ajax({
        type: formMethod,
        url: formAction,
        data: data,
        success: function() {
            console.log('success!'); // or not!
        },
        error:function (xhr, ajaxOptions, thrownError){
            console.log(xhr.status); // 0
            console.log(thrownError); // empty
        }
    });
});

of course I'm getting a cross origin error since I'm attempting to submit to another server via JS. I do have access to an API key but not sure if or how to use it in this instance.

0

Did you try white listing the post URL in Remote Site Settings in salesforce. If not yet done, please try that. Also in this spring 15 release salesforce has started supporting "Cross Origin Resource sharing(CORS). Please have a look at that also.

https://success.salesforce.com/ideaView?id=08730000000ZojFAAS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.