Jquery getJSON to external PHP page -
I am trying to make an AJAX request on an external server. I have learned so far that I need to use getJSON to do this because of security reasons?
Now, I can not seem to call an external page a simple call. I've tried to make as easy as I can, but it still does not work. I have 2 files, test.html & amp; Test.php
My test.html builds on this type of call on a local host for testing:
$ .getJSON ("http: // localhost / outvoice / Services / Test.php ", Function (JSN) {Warning (" Jason Data: "+ JSN);}); And I have to return my test.php a simple 'test':
$ results = "test"; Echo json_encode ($ result); I'm probably making some incredible rookie mistake but I can not find this. Also, if this works, then how can I send data to my test.php page, such as test.php? Id = 15?
Test.html Page Testing .php page on local host, the same directory I did not find any errors, just no warning.
< Div class = "post-text" itemprop = "text">
It may be be that you do not get a callback in test.php. In addition, json_encode accepts only one array:
$ results = array ("key" => "value"); Echo $ _GET ['callback'] '(' .json_encode ($ result). ')'; // If you are requesting different domains, callback stuff is only required jQuery automatically switches to JSONP (i.e. XMLHttpRequest instead of Using the script tag) When you use http: // if you have test.html and test.php on the same domain, then use the relative path (and any callback) try.
Comments
Post a Comment