1

My javascript code looks like below :

function copysave(){
    dojo.io.iframe.send({
    form:dojo.byId("formId"),
    method: "POST",
    //handleAs: "html",
    encoding : "utf-8",
    url :"/CopyReplace/copysavefirst",
    load: function(response) {
        txtResponse = response;
        alert("respone: "+txtResponse);
        console.log(" success : txtResponse"+txtResponse)
    },
    error: function(error, ioArgs) {
        console.log("bulkcopy() ERROR :: " + error);
        console.log("bulkcopy() ioArgs :: " + ioArgs);
        return error;
    }
  });
}

My Html looks like below :

<form enctype="multipart/form-data" id="formId" method="">
<button name="save" id="submitValues" value="Finish" onclick="copysave()" >Finish</button>

If I click on finish, I can see /CopyReplace/copysavefirst hitting the server two times. Could some one please tell me what to do to call only once? Also, it is going to the error section.

M Hamza Javed
  • 1,249
  • 4
  • 14
  • 28
P H
  • 155
  • 1
  • 12
  • Look for type one would be OPTIONS and one would be POST in cross domain prior to any call an option call is an pre-flight request – Vinod Louis Feb 10 '17 at 05:40
  • Probably the first call is just a HEAD request and then it gets a 100-continue, to which it replies again, this time with the POST data. – Nehal J Wani Feb 10 '17 at 05:44
  • @Nehal I am actually triggering a job for this. So, it's getting called twice and the job is triggered twice. – P H Feb 10 '17 at 05:50
  • @VinodLouis I didn't get you. I should use OPTIONS? – P H Feb 10 '17 at 05:50
  • @POOJAHEGDE no 2 calls will be made when you do a cross doamin request the option call is a pre-flight request to check the cors access later follwer by the real POST/PUT/GET/DELETE call inspect the network console you will see OPTIONS and POST call – Vinod Louis Feb 10 '17 at 05:52
  • try using enctype="text/plain". – Shoaib Konnur Feb 10 '17 at 05:54
  • @POOJAHEGDE Look in browser console if you see two calls you can see there one would be for `OPTIONS` and other would be `POST` – Mairaj Ahmad Feb 10 '17 at 05:55
  • @POOJAHEGDE for better understanding go through it http://stackoverflow.com/questions/1256593/why-am-i-getting-an-options-request-instead-of-a-get-request – Vinod Louis Feb 10 '17 at 05:57
  • @VinodLouis I checked both the calls. Both are returning the same response data from server. Even though I am receiving 200 response code for both the calls, I am getting error logs in error callback(). Instead of allowing a pre-flight, can't we just call the real POST req? – P H Feb 10 '17 at 06:08
  • @ POOJAHEGDE which language are you using on the file which is calling by ajax? – Varun Malhotra Feb 10 '17 at 07:31

0 Answers0