JavaScript "Access Denied" JSON Ajax Error in IE

Hey Guys,

I can't seem to get this to work in IE for some reason. I get the "Access Denied" Error. I have looked around and it seems like it may need to be jsonp in order to work but I can't seem to get jsonp to work (or am doing it wrong). This works GREAT in Firefox, Chrome, Safari, etc. But not IE.

Can someone help me write the code so it works in IE as well?

Thanks,

Mike


$.ajax({
  			 type: "GET",
  			 url: "http://www.mywebsite.com/",
  			 dataType: "json",
			 success: function(json){
     			shrink_it();
   				},
			error: function(json){
				shrink_it_error();
			},
			data: data_value
			});
	};

Open in new window

mfgoalieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Could you confirm you do the call to the same domain ? Your page and the ajax script is on the same domain ?
0
mfgoalieAuthor Commented:
Sorry, forgot to mention that, the call is actually going to a different domain. Not the one that the file is resting on.

Thanks
0
leakim971PluritechnicianCommented:
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mfgoalieAuthor Commented:
Hmm, I went through and read that, thanks! The issue I am having is that I use the .getJSON call on another page in the same website and that works perfectly. But is it possible to send data to the other website using .getJSON? How would I reformat that .ajax call into .getJSON or jsonp so that it works correctly?

Thanks!
0
leakim971PluritechnicianCommented:
You may use a "php proxy" in the same website that download the external content () for your and return it back to your page. :

update field_1_from_data, ....., field_n_from_data

Confirm your URL too :  "http://www.mywebsite.com/"
What's the default page ? index.php ?
<?php
   echo file_get_contents('http://www.mywebsite.com/index.php?field1=' . urlencode($_GET['field_1_from_data']) . "&fieldn=" . urlencode($_GET['field_n_from_data'])  );
?>

Open in new window

0
leakim971PluritechnicianCommented:
0
mfgoalieAuthor Commented:
Hey Leakim971,

Thanks for all the help! I have been trying to play with what you sent me for the last few days and can't get it to work. Even copying the sample text provided via the link you sent me doesn't work. I just get a blank alert. Although, when I load the page,  the variable "search" does get sent to the file "fetchFile.php". But from there, the information is not passed back to the original html document to alert.

Isn't there a way to just add jsonp or callback=? to my javascript to allow it to get information from another domain? Is there a way to do it using JQuery's .getJSON?

Thanks again!,

Mike
0
leakim971PluritechnicianCommented:
Ensure you get results when you call the php proxy page directly with valid parameters.



0
mfgoalieAuthor Commented:
I changed my fetchFile.php to say the following. Now it returns something like:

You Searched paris+hilton to http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=paris+hilton

But for some reason, isn't actually doing the search. Charles Web Proxy shows that it isn't even trying to contact wikipedia with the desired information, which makes it seem like the error is in my file_get_contents (which it isn't doing).

Thanks,

Mike
<?php
//fetchFile.php
$search = urlencode($_GET['search']);
$search_file = 'http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=' . $search;
$search_response = file_get_contents($search_file);
echo "You Searched " . $search . " to " . $search_file;
echo $search_response;

?>

Open in new window

0
leakim971PluritechnicianCommented:
>Now it returns something like
With an alert or when your type the url ?
0
mfgoalieAuthor Commented:
When you type the URL.

For me, I type http://localhost/test/fetchFile.php?search=paris hilton.

I have MAMP running on my computer so my localhost setup can run php files.

Thanks,

Mike
0
leakim971PluritechnicianCommented:
Enable php warning and/or check if file_get_contents return false.
Do you have curl enabled ?

0
leakim971PluritechnicianCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mfgoalieAuthor Commented:
THanks!! That was it. I had CURL installed correctly and it all works perfectly. Here is the final code I used. Thanks for the help!
<?php
error_reporting(-1);
//fetchFile.php
$search = urlencode($_GET['search']);
$search_file = 'http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=' . $search;
?>

<?php
ob_start();

function logf($message) {
  $fd = fopen('proxy.log', "a");
  fwrite($fd, $message . "\n");
  fclose($fd);
}

?>

<?php
$url = $search_file;
logf($url);
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, "Mike's AJAX Proxy");

$content = curl_exec($curl_handle);
$content_type = curl_getinfo($curl_handle, CURLINFO_CONTENT_TYPE);
curl_close($curl_handle);
header("Content-Type: $content_type");
echo $content;
ob_flush();
?>

Open in new window

0
mfgoalieAuthor Commented:
Perfect. Great help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.