Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3801140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:00:10+00:00 2026-05-19T14:00:10+00:00

Greetings all, I’m an AJAX newbie, and I’m having a problem with same origin

  • 0

Greetings all,

I’m an AJAX newbie, and I’m having a problem with same origin policy protection using JQuery 1.4.4 and the jquery.form.js AJAX plug-in.

I have an AJAX contact form which works fine so long as visitors preface URL’s they type in with “www”. But if they navigate to my site (not using www), the URL still resolves OK but the URL doesn’t match what I use in my AJAX form. In Chrome, this results in a console error:

“XMLHttpRequest cannot load http://www.example.com/. Origin http://example.com is not allowed by Access-Control-Allow-Origin.”

And on IE8 I get “Access is denied”. So even though the URL’s resolve OK with or without “www”, my AJAX form won’t work if the visitor doesn’t preface with “www”. If I change my AJAX form code to post to http://example.com (without “www”) then it won’t work if visitors navigate to http://www.example.com. I can’t think of how to make my code handle either condition. This has got to be an issue that nearly everyone would run into who is using AJAX, regardless of using JQuery. So I must be missing something obvious. Can someone please educate me on this? My test code is below.

Thanks,

Northk

<!DOCTYPE html> 
<html>
<head> 
<meta charset="utf-8"> 
<title>ajaxForm Error Test</title> 
<script src="http://www.example.com/js/jquery-1.4.4.min.js"></script> 
<script src="http://www.example.com/js/jquery.form.js"></script>    
</head> 
<body>
<form id="contact-form" method="post" action="http://this-url-wont-be-used.com/">
<a href="#" id="contact-button">SEND</a>
</form>
<script>
//
// hook up the form to ajax
//
$('#contact-form').ajaxForm({
    url: 'http://www.example.com/', // forcing the URL doesn't seem to help!
    success: function(data) {
        alert(data);
    },
    dataType: 'html'
});
//
// make the SEND link behave as if it's a submit button
//
$('#contact-button').click(function(e) {
  $('#contact-form').submit();
});
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:00:10+00:00Added an answer on May 19, 2026 at 2:00 pm

    The domain http://www.xyz.com and the domain xyz.com are not the same so you’ll get this error if you’ve hardcoded urls in your Javascript files.

    The short answer is ot use relative urls rather than full urls. You don’t show actual urls so I can’t give you an exmaple in your case but lets say the the domain was
    http://www.xyz.com
    and you need to post the form to the url
    http://www.xyz.com/admin/form/

    In your javaScript the url you’d use is
    /admin/form

    That way no matter what url your visitor uses to get to your site it will work and it won’t result in a cross domain scripting error.

    Of course if your site is public you should probably (permanently) redirect your xyz.com site to the http://www.xyz.com site. Because Google and other search engines consider these two to be different domains and your page ranks will be divided across the two domains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files
Greetings On all my controllers I recycle the same code that wraps my models
greetings all i have a problem that when sending an email from the server
Greetings All! I am having some troubles on how to execute thousands upon thousands
greetings all i have a web application using (spring-hibernate) frameworks and when tried to
Greetings I am a jquery newbie and trying to fix an issue which uses
Greetings all. I am writing some code using the Boost Units library and have
Greetings All; I am a beginner in using regex. What I want to do
Greetings all, In my application,user can open several QWindows which share the same data.(save
Greetings all i have a j2ee app using spring framework and while debugging on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.