Javascript: How to test JSONP on localhost
Posted
by
hqt
on Stack Overflow
See other posts from Stack Overflow
or by hqt
Published on 2012-06-16T15:06:35Z
Indexed on
2012/06/16
15:16 UTC
Read the original article
Hit count: 247
JavaScript
|jsonp
Here is the way I test JSONP: I run XAMPP, and in folder htdocs I create a javascript folder . I create json1.json
file contain some data to process.
After that, I run this html file locally, and it will call a function in "other machine" (in this case is localhost
)
Here is my code :
<head>
<script>
function updateSales(sales) {
alert('test jsonp');
// real code here
}
</script>
</head>
<body>
<h1>JSONP Example</h1>
<script src="http://localhost:85/javascript/json1.json?callback=updateSales"></script>
</body>
But when I run, nothing happen. But if change to other real json on the internet, it will work. It means change line :
<script src="http://localhost:85/javascript/json1.json?callback=updateSales"></script>
to line:
<script src="http://gumball.wickedlysmart.com/?callback=updateSales"></script>
It will work smoothly.
So, I don't know how to test JSONP
by using localhost, please help me.
Thanks :)
© Stack Overflow or respective owner