Jump to content

SOAP web service and JQuery/Ajax


chapp77

Recommended Posts

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:

 

<?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:

 

function AjaxCall() {
    $.ajax({
        type: "POST",
        url: "phpRelay.php/LoginToAccount",
        data: "{email : '[email protected]', 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);
}

Link to comment
https://forums.phpfreaks.com/topic/238970-soap-web-service-and-jqueryajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.