Strange problem with jQuery ajax post - javascript

I have very strange problem and that problem occurs very rarely and that too in our production env.
The production env. setup is,
Apache Web Server as front layer
Apache Tomcat 6.0 as application server (liked with Apache Web server via mod_jk)
I have custom made Ajax based RPC component where we use jQuery for ajax calling. The data is communicated using POST method.
The client side data (javascript objects) are sent to server in JSON format and on server side they are deserialized into java objects.
The RPC call is executed by providing following information,
var jsonParamObj = new Object();
jsonParamObj.param0 = objParam0;
var params = new Object();
params.**jsontext**=**toJsonString**(jsonParamObj);
where jsontext contains the real data to be transmitted. I am using toJsonString javascript function available as open source json script (previously used JSON.stringify but had same problem).
Following is the jQuery call,
$.ajax({async:async,
data:params,
dataType:"json",
type:"POST",
url:this.ajaxAction+qs,
contentType:"application/x-www-form-urlencoded; charset=UTF-8",
error:function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Connectivity Issue : '+textStatus + ' Error : '+errorThrown + ' Response : '+XMLHttpRequest.responseText);
},
success:function(jsonobj){
if(jsonobj.JSON.ajaxSysError)
{
alert(jsonobj.JSON.ajaxSysError.message);
return;
}
// do other work
}
});
Now the problem is sometimes whatever data sent in forms of params do not reach to server (not to apache as well as tomcat) I have enabled maximum level of verbosity in logs however whatever data it sends through query string (see qs) reaches server.
The client browser is IE 7 (Windows XP Media Edition).
Can you put some thoughts that would help me in debug this issue.
Thanks for reading this long question.
Jatan

Install Fiddler and look at the HTTP request that IE is sending.
Also, put the ajax call in a try/catch block and check whether you're getting any Javascript errors.

Related

How to call a function written in C with axios?

I’ve used a microcontroller to develop the embedded web server and I’m not sure if I can download an Apache or any other server into my controller.
However, I’ve successfully implemented an HTTP interface and have been hosting web pages and handling & parsing the POST request data/payload at the embedded web server side.
The issue is coming when the web page contains any form type data to be submitted.
I receive the value(s) entered by the user on the web page but I'm not able to display the data properly on the web page sent by the embedded server.
That’s where there’s a major issue in linking C (freeRTOS) code (server side) and JS (client side).
How can a JS web client pull data from embedded web server (in freeRTOS) given that I have a successful HTTP connection established with the web page and I'm also able to host pages as mentioned above?
Currently I'm using axios but unable to figure out how to call a C function in the URL? As it's not possible to code in C without a function.
axios({
method: 'post',
url: 'getStatus.c',
data: sampleData,
headers: {'Content-Type': 'multipart/form-data' }
})
.then(function (response) {
console.log(response);
})
You cannot directly call a function in uncompiled C source file.
axios is a client side ( JS lib ) technology. Any server side program that you want to interact with axios must implement some sort of HTTP interface.
If you must use C to achieve something like that:
Implement a CGI interface in C
CGI program can as simple as something like this ( Handling POST request is bit more difficult ):
#include <stdio.h>
int main()
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<body>\n");
printf("<h1>Hello there!</h1>\n");
printf("</body>\n");
printf("</html>\n");
return 0;
}
You can access POST request data the following way:
len_ = getenv("CONTENT_LENGTH");
len = strtol(len_, NULL, 10);
postdata = malloc(len + 1);
if (!postdata) { /* handle error or */ exit(EXIT_FAILURE); }
fgets(postdata, len + 1, stdin);
/* work with postdata */
free(postdata);
How to retrieve form "POST" data via cgi-bin program written in C
More on CGI C programs: http://jkorpela.fi/forms/cgic.html
Consider using libcgi http://libcgi.sourceforge.net for CGI C programs.
Compile the CGI program.
Use Apache2 or Nginx to serve the CGI "script" in this case the compiled binary.
If using C is not a priority:
I would recommend to use a high level language which is more suitable for web development. Python / PHP / C# / Java / etc..

Execute php code on different server via javascript

As part of my third year project for university I am creating a HTML5 Web App for the amazon fire tv OS. This web app is supposed to communicate with another remote server to update another client with information about what the user is currently watching. I have succesfully implemented this communication using socket.io on localhost but unfortunately the android OS does not support web sockets, so I cannot use socket.io within the fire tv app itself.
To get around this I thought about having a php file on my server that will emit the socket request when a relevant GET request for the page is requested. The php code for the file is below:
if(isset($_GET['title'])){
echo "
socket.emit('vidStart', '" . $_GET['title'] . "');
";
}
echo "</script>";
As you can see all the code does is emit when the page is requested using a title parameter.
Now, this works fine when I go to the web browser myself and enter the url, the emit succeeds and my server receives the message.
However, I am trying to execute this on the server remotely using javascript, to get around having to use socket.io in my fire os app.
The code I currently have in my app is below:
$.ajax({
'type': 'GET',
'url': 'http://138.68.175.172:81',
'data': 'title=example',
success: function(response){
console.log(response);
}
});
This returns the correct response but doesnt seem to actually execute the php code and emit via socket io on my server. My question is, is this possible to do via javascript and php? I have tried looking at XMLWebRequest but it seems to do the same thing, and responds with the web page.
If this isn't possible, is there any other way to send information to a remote server, and have it execute a command ( in this case emit a socket.io message)?

Consume PHP web service with javascript (client side programming) Sharepoint

I'm not familiar with Web Services. My company wants to integrate SharePoint 2013 to SAP. My company (right now) only allow us to develop SharePoint app using client side programming (JavaScript).
We already have some PHP application connect to SAP through RFC, so my idea is creating PHP web service and consume it from JavaScript (SharePoint).
My Question :
1. Can we do that?
2. Is there another ways to integrate SP to SAP with Client Side Programming?
I tried simple JavaScript calling php function (not a webservice) using Ajax below, but having error (alert:error2).
$.ajax({
type : "POST",
url : "http://10.15.5.150/testapp/test_ws",
data : "id=1",
cache : false,
success : function(data){
var data = eval('('+data+')');
if(data.success){
alert(data.msg);
}else{
alert('error');
}
},
error: function(data){
alert('error2');
}
});
Thanks.
Consuming a PHP web service is most definitely possible with having javascript as a client. It is especially simple if you can make use of the JQuery library in javascript. This Library will give you simple tools you need to create ajax requests to the PHP service.
If the PHP Web Service is hosted on another domain, (Other than the SharePoint domain) the SharePoint server providing the Javascript needs to include the following header.
"Access-Control-Allow-Origin: <domain-of-php>"
Note: the domain can also be * for all domains.
This header will allow the browser to connect to other domains other than the original domain.

sharePoint online count unread message from office365

As part of a project whose aim is to notably improve the visual side of a SharePoint Online site, I'm a bit stuck. On the home page in the left banner, users want to see the number of unread messages they have in Office365.
I created an area in the master page to put the result in. I thought the Rest API used to do this :
$.ajax ({
type: "GET",
url: " https://outlook.office365.com/ews/odata/Me/Folders/Inbox",
dataType : "json",
success : function (resp) {
// count unread messages
},
error : function (e) {
alert (' Error121212 :' + JSON.stringify (e));
}
})
Unfortunately I get an error like cross domain. I tried with JSONP but it does not work either (uncaught syntax error unexpected token).
Can you please tell me if this is a good practice? I feel that it anyways I must find a technic for authentication. (In the case of JSONP I have a popup that asks me authentication and then problem occurs on callback apparently)...
I want to avoid developing a type requiring a typical deployment Wsp...
Thank you in advance for your help.
Your URL for the ajax request seems incorrect. The URL for getting the inbox messages via the API is: https://outlook.office365.com/api/v1.0/me/folders/inbox/messages
Once you get the response, you can count the number of objects with the IsRead property set to false using a simple for loop and display that count.
The issue here is related to CORS and how browsers refuse to handle cross-domain requests. To get around this, typically you would either
Change the response header on the remote server - not an option here
Use some sort of proxy to handle the requests - here's where SharePoint apps come in.
I know you stipulated that you want to avoid using a WSP style deployment but there simply isn't a way around it, you have to use the SharePoint App Model
This article goes a long way to answer your question, but for completion the basic steps are as follows
Create a SharePoint hosted app in Visual Studio
In the App Manifest, you need to define the trust relationship with the remote host (in this case the host of outlook.office365.com) using the AppManifest section
Use SP.RequestExecutor.executor to make the request on your behalf

What is the best/proper configuration? (javascript SOAP)

I need to retrieve data from a web service (via SOAP) during a nightly maintenance process on a LAMP server. This data then gets applied to a database. My research has returned many options and I think I have lost sight of the forest for the trees; partially because of the mix of client and server terms and perspectives of the articles I have read.
Initially I installed node.js and node-soap. I wrote a simple script to test functionality:
var soap = require('/usr/local/lib/node_modules/npm/node_modules/soap');
var url = "https://api.authorize.net/soap/v1/Service.asmx?WSDL";
soap.createClient(url, function(err, client)
{
if(typeof client == 'undefined')
{
console.log(err);
return;
}
console.log('created');
});
This uses a demo SOAP source and it works just fine. But when I use the actual URL I get a 5023 error:
[Error: Invalid WSDL URL: https://*****.*****.com:999/SeniorSystemsWS/DataExportService.asmx?WSDL
Code: 503
Response Body: <html><body><b>Http/1.1 Service Unavailable</b></body> </html>]
Accessing this URL from a browser returns a proper WSDL definition. I am told by the provider that the 503 is due to a same-origin policy violation. Next, I researched adding CORS to node.js. This triggered my stepping back and asking the question: Am I in the right forest? I'm not sure. So, I am looking for a command-line, SOAP capable, CORS app (or equivalent) configuration. I am a web developer primarily using PHP and Javascript, so Javascript is where I turned first, but that is not a requirement. Ideas? Or, is there a solution to the current script error (the best I think I have found is using jQuery in node.js which includes CORS)
Most likely, this error belongs to your website server.
Please go through this link, it might be helpful.
http://pcsupport.about.com/od/findbyerrormessage/a/503error.htm
Also you can open your wsdl in web browser, search for soap:address location tag under services. And figure out correct url, you are trying to invoke from your script. Directly access this url in browser and see what are you getting.
I think I have a better approach to the task. I found over the weekend that PHP has a full SOAP client. I wrote the same basic login script in PHP and it runs just fine. I get a valid authentication code in the response to loginExt (which is required in further requests), so it looks like things are working. I will comment here after verifying that I can actually use the web service.

Categories

Resources