Solved

jquery ajax json request

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

Expert Comment

by:Rob
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 43

Accepted Solution

by:
Rob 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

809 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