Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

SOAP web service and JQuery/Ajax

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

SOAP web service and JQuery/Ajax

Postby chapp77 » Fri Jun 10, 2011 3:38 am

I have a PHP SOAP web service acting as a relay to call cross domain web services. The problem I'm having is calling my local PHP web service methods from JavaScript (using JQuery/Ajax). I want to call a specific method in my web service; e.g. "LoginToAccount";

I'm NOT interested in appending params in the url and then figuring out which method to call... This is very straight forward in .NET (mywebservice.asmx/LoginToAccount") but can't figure it out how to get this to work in PHP.

I continually get a "500 Internal Server Error" of "Bad Request": Bad Request

Here is my PHP code:

Code: Select all
<?php

function LoginToAccount($email, $passCodeHash) {
    //...code calling cross-domain web services
    return $jsonEncodedResponse;
  }


function CreateAccount($email, $passCodeHash){
    //...code calling cross-domain web services
    return $jsonEncodedResponse;
}

$server = new SoapServer(null, array('uri'  => "http://www.myurl/webservices/"));

$server->addFunction('LoginToAccount');
$server->addFunction('CreateAccount');
$server->handle();
?>


Here is my JavaScript code:

Code: Select all
function AjaxCall() {
    $.ajax({
        type: "POST",
        url: "phpRelay.php/LoginToAccount",
        data: "{email : 'myEmail@email.com', passCodeHash: '12345'}",
        contentType: "application/json",
        dataType: "json",
        success: succeeded,
        error: queryError
    });
}

function succeeded(data, textStatus, request) {
    var result = $.parseJSON(data.d);

}

function queryError(request, textStatus, errorThrown) {
    alert(request.responseText, textStatus + " " + errorThrown);
}


This is all on the same domain. Thanks!
chapp77
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Jun 10, 2011 3:34 am

Re: SOAP web service and JQuery/Ajax

Postby johnj » Fri Jun 10, 2011 6:17 am

You are already passing email and passCodeHash. Just pass methodName along with it like this
Code: Select all
        url: "phpRelay.php",
        data: "{email : 'myEmail@email.com', passCodeHash: '12345', methodName: 'LoginToAccount'}",
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: SOAP web service and JQuery/Ajax

Postby ramkumarlaks » Mon Nov 18, 2013 3:42 am

I'm having wsdl file for web service,Can't i use like this

$(document).ready(function() {
$("#submit").click(function(){

var formData = $("#callAjaxForm").serialize();

$.ajax({
type: "POST",
url: "http://localhost/jeemasmsmobile13112013/test.wsdl",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
return false;
});


And my server file is

<?php
if(!extension_loaded("soap")){
dl("php_soap.dll");
}

ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer("test.wsdl");

function doHello($user,$pass){

$name= $_POST['name'];
$pass= $_POST['pass'];
if($user == 'admin' && $pass == '1'){
return 'success';
}else{
return 'failed';
}
}

$server->AddFunction("doHello");
$server->handle();
?>


If not what is the use of web service here.We can directly call the php method.Please correct me if am wrong.
ramkumarlaks
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Nov 18, 2013 3:37 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron