0

I am submitting the form using jquery. Now i need to send form information into external server. The below is the part of my code that submit the form to another server. It works in all browsers except IE which gives me access denied error.

$.ajax({
    url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
    type:'POST',
    data:"ID=" + $ID + "&Source=" + $Source + "&notifyCc=" + $notifyCc + "&notifyBcc=" + $notifyBcc + "&noMail=" + $noMail + "&CFirst=" + $first + "&CLast=" + $last + "&Phone=" + $Phone + "&Fax=" + $Fax + "&CEmail=" + $CEmail + "&Message=" + $message,
    success: function() {
    }
});

Any help?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Naveen
  • 125
  • 3
  • 13
  • If you are POSTing a form; you should definetely use `$("#myForm").serialize()` (http://api.jquery.com/serialize/) – Mustafa Jun 30 '11 at 14:50
  • How can you tell it's working in other browsers? I suspect it's not working in any of them, they just suppress the error better. – Shadow The GPT Wizard Jun 30 '11 at 14:52
  • @kasdega indeed.. many people are not aware of the JavaScript Console thus they think all is working properly in FF or Chrome. :-S – Shadow The GPT Wizard Jun 30 '11 at 14:57
  • Well i am able to insert data in external database although i got error (302 object moved) in case of firefox/chorme but in case of IE data is not entering in external database. In IE i got a Access denied error. So what should i do now? – Naveen Jun 30 '11 at 16:09
  • @Naveen see Nick's comment to my answer...With some browsers apparently you can actually POST to an external domain but not see the result. So you're external site could be getting the POST and storing the data but you can't pull back and view anything. – kasdega Jun 30 '11 at 16:12
  • So kasdega what you suggest me to do? – Naveen Jun 30 '11 at 16:13
  • I would build a proxy. here is an answer that provides JSP code to do just that. http://stackoverflow.com/questions/6523162/jquery-ajax-get-returns-405-method-not-allowed/6523587#6523587 – kasdega Jul 09 '11 at 15:52
  • One more thing i forgot to mention that in case of firefox/chrome i got 302 object moved error. in spite of that error i am able to insert data in external database server where as in case of IE i got access denied error. But Data is not inserting in case of IE. Do you still think proxy is the real problem?? – Naveen Jul 11 '11 at 11:39

1 Answers1

3

You can not make an AJAX call to a different domain. See my answer here: jQuery ajax GET returns 405 Method Not Allowed

That being said if it truely works in other browsers then I'm assuming you're posting to the same domain. Then you have to look at the returned content. There should be no reason you'd get a 405 from IE but not from FF.

I suspect though that this doesn't work with other browsers either, because of the javascript security restrictions.

Community
  • 1
  • 1
kasdega
  • 18,396
  • 12
  • 45
  • 89
  • 2
    This isn't *strictly* true, there are two sets of restrictions in play here, and it depends which one you're doing. A) Can you POST at all? and B) can you see the result? It depends on the browser, domain and protocol, but some let you do A cross-domain, though none let you do B (by default). So in some cases you *can* POST, just not see the result. – Nick Craver Jun 30 '11 at 15:21
  • @Nick Craver interesting I didn't know A, I'll have to research that. Thanks for the tip. – kasdega Jun 30 '11 at 15:25
  • Well i am able to insert data in external database although i got error (302 object moved) in case of firefox/chorme but in case of IE data is not entering in external database. In IE i got a Access denied error. So what should i do now? – Naveen Jun 30 '11 at 16:12
  • @Naveen the explanation of the behavior you're seeing is in Nick's comment. Other browsers are able to POST to the external service but can't get a response. IE can't/won't POST externally at all. You need to look into creating a proxy of some kind to make the external connection for you. See my answer for a similar problem that I linked to in this answer. – kasdega Jul 09 '11 at 21:47
  • One more thing i forgot to mention that in case of firefox/chrome i got 302 object moved error. in spite of that error i am able to insert data in external database server where as in case of IE i got access denied error. But Data is not inserting in case of IE. Do you still think proxy is the real problem? – Naveen Jul 11 '11 at 11:40