Solved

jquery ajax json request

Posted on 2013-11-19
3
854 Views
Last Modified: 2013-12-04
Hey trying to setup an ajax request to retrieve json from my json file. not sure what im missing. this is a local test on my machine.

error message:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

I'm confused on how to resolve this.

html:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title> Twitter Module</title>
    <link rel="stylesheet" href="css/styles.css">
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="js/script.js"></script>
  </head>
  <body>
    <!-- Twitter Moddulue -->
	<div id="twitMod" class="twit-module clrfix">
		<div class="twit-header">
			<h2>PCH Tweets Homework </h2>
		</div>
		<div class="twit-feed">
			<div class="tweet">
				<img src="" width="49" height="49" />
				<p class="handle">@fatherconfessor</p>
				<p class="tweet-text">roses are red violets are purple, why am i reciting this poem</p>
			</div>
		</div>
		<div class="twit-footer">
			<span class="refresh"></span>
		</div>
	</div>
  </body>
</html>

Open in new window


javascript:

$(document).ready(function(){

	$.getJSON( "js/pch_twitter_response_2.json", function( data ) {
		console.log(data);
	});
});

Open in new window

0
Comment
Question by:JMRFan4Life
  • 2
3 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39661469
Are you using with a file:// address?  Because it won't work.  It thinks it's a different domain.
Have you tried jsonp?
0
 

Author Comment

by:JMRFan4Life
ID: 39661479
yes this is setup locally on my machine.

im sorry but not sure how to setup/implement jsonp. could you please provide some guidance.


PLEASE HELP ME!

I'm really confused!!!

thanks
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 39661541
This will not work period with file:// You either need to set up a web server on your local machine or put the code on a webserver
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now