how to call a web service written in php in javascript?
Hi I have web service that is written in php that outputs my data in xml format. I 开发者_运维知识库need that data to be send to an html page where I use javascript to display it. I want to know to how call that php service from my html page using javascript?
You can use JSON and PECL for data transfer with php
JSON http://www.json.org
Scroll down to the page to see some options that you have for PHP.
If you wanted to do something fast and simple, you can use the jquery get or post call to acheive the disired result:
jQuery GET: http://api.jquery.com/jQuery.get/
The get and the post both have a call-back function which can be used to accept the result of loading your php page and then you can determine how to display it.
You should have a way or create a way to access that by going to a specific URL. So just create some JS that will call that URL. Best to use JQuery to make things easier. Then just manipulate the data all you want.
Try that .ajax function from JQuery. There are some great examples at http://visualjquery.com/. You can also get more details on it from http://api.jquery.com/jQuery.ajax/
Example:
var html = $.ajax({
url: "some.php",
async: false
}).responseText;
You could also use JQuery's load function:
$('#result').load('ajax/test.html');
How about something like this using jQuery's load()
?
$('#result').load('http://myWebService/serviceName.php');
<div id="result"/>
精彩评论