I have been using ajax to communicate with a web service, but it seems on one of the pages I have I may have to use PHP instead. Could I get help to change the ajax script below to PHP instead. have googled it and there seems to be many ways, but nothing fits what i want so I can learn from it and try it.
Sure there is - you submit your form to a PHP page on your server, which can then make the request (using cURL, or a wrapper library such as Guzzle) to the web service.
Just a shot in the dark, but are you having problems with making a cross domain request?
Ye thats what is happening, the user selects the hotel to get a report on, and on click of request the hotel ID, the user ID and a few other details are passed to a php page and there an email script on there too, but need to add these details to the web service.
Well everywhere else this script works perfectly, then when I added it to the php page dealing with the form values, it doesnt work, so thought i would tie it in with the php rather than having ajax on there.
Iām wondering if its maybe because the page does its email script and then its redirected back, so could it be that there not enough time to connect to the web service to do its stuff.
Have you got a cURL example fretburner similar to what I need
I think youāll probably be best using a basic wrapper library, like this one: https://github.com/shuber/curl which makes working with cURL more user-friendly.
The library seems to have a good README, so you should be able to get up and running with the instructions there.
Hi you know with the code above, i have got it to work now and I have been told that I dont get a success response back, so is it possible as the last line of code to redirect to a new url.
So success: onDataRecieved is now not needed as there no data recieved in this case, just really I need to redirect once it reaches the last line of code.
After many developers warned me about what I was doing i have to change from getting the data from a web service using jquery, instead I need to use php, so am making a start now to change everything around.
I have the jquery below
$.ajax(
{
crossDomain: true,
contentType: "application/json; charset=utf-8",
url: "http://dev.mysite.com/WebService.asmx/TC_GetPropertyData",
data: {id: "12345"},
dataType: "jsonp",
success: onDataReceived
});
function onDataReceived(data)
{
if (data != 0){
var stuff = data;
var properties = stuff.split("|");
var propertyDetails = properties[1].split("/");
var obj = {Id_Hot: propertyDetails[1], Nom_Hot: propertyDetails[2], IdCat_Hot: propertyDetails[3], Dir_Hot: propertyDetails[4], IdRsrt_Hot: propertyDetails[5], IdRsrt_Hot: propertyDetails[6], IdCntry_Hot: propertyDetails[7], TourCheckPublished: propertyDetails[8]};
//alert (obj);
$.post("empty-Display.php", obj);
}};
So instead of above i want to use php, so have made a start with below, and I just wanted to know if I was on the right track
Is the site youāre connecting to having trouble with the request? That is, I notice youāre using JSONP in the js code, and while I know nothing of it, that seems to be specific to get around an issue with requests from a different domain than the server, and I wondered if it was related.
Ye good point actually, and I was struggling for days with it, and finally found a bit of code and noticed they used jsonp instead of json, added the p and it connected straight away.
System.InvalidOperationException: Missing parameter: callback. at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
I added
curl_error();
and got this extra bit of feedback
Warning: curl_error() expects exactly 1 parameter, 0 given in
and just to remind the jquery above which Im trying to change from, works fine, so the id is correct, so there something that Im doing correctly in the jquery that im not doing in the php
Ah ye, changed that and it made no difference to the main error. Umm the error appears as I started using this code, I took curl_error out and it left that error still there, the error is being echoād out from $result
System.InvalidOperationException: Missing parameter: callback. at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
OK, so that isnāt an error with your code specifically, itās the error message that the remote server is giving you when you attempt to call it. If you open a browser window and type in that URL exactly as in the CURL code, do you get the same error or does it appear to work?
That would explain the āmissing parameter: callbackā part of the error message, but I donāt really have enough knowledge to understand what that Wiki page talks about, and where the āparseResponse()ā function resides.
Ye I was hopeful on that then, as i understand what you saw and what i didnt have, but unfortunatly it still shows the same chunk of information
System.InvalidOperationException: Missing parameter: callback. at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Thanks though droopsnoot, and if I put it directly into the broswer, I get the same chunk of information
Actually now Iāve read that page again, it makes a little bit more sense. It doesnāt seem to make any sense that itās causing this issue, since it seems to be more concerned with how your code interprets the return from the page, and you said earlier that there isnāt any return - calling the URL just tells it to send an email to a user identified by ID.
My next thought would be to ask whoever supports the remote site why you canāt access the page the way you have been doing. The fact that it gives you the same error message from a browser implies that it isnāt the CURL code.
So then I use split to break up the data into packages, but that above is basically everything that is in that database and how I get it using the ajax.
I was then in php going to use explode to break it up into packages then from there I need to feed it into another select statement, but thats for another day.
I reverse engineered the connecting url and we have come to the conclusion that it maybe the id, now I cant post it here but it is the correct id but it does have a few &'s in there, which maybe causing the problem, but I know that I could also be wrong.