Solved

jquery ajax json request

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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 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)

737 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