Solved

jquery ajax json request

Posted on 2013-11-19
3
842 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

762 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

23 Experts available now in Live!

Get 1:1 Help Now