Solved

jquery ajax json request

Posted on 2013-11-19
3
871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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 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…

688 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