Is this proper when making an ajax request via ruby to use two params?
function drawIt(one_id, quest_id){
var request = $.ajax({
url: "/reer/porip?rn_id=" + one_id + "?two_id=" + quest_id,
type: "GET",
dataType: "json"
});
it's ok, however you have double ? char in url. It should be:
url: "/reer/porip?rn_id=" + one_id + "&two_id=" + quest_id,
parameters in url are separated by &
Related
I am trying to intercept response messages in Swagger using this code:
var full = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
var ui = SwaggerUIBundle({
url: full + "/swagger/v2/swagger.json",
responseInterceptor: function (resp) {
console.log('#response');
return resp;
},
onComplete: function () {
console.log('#onComplete');
}
});
The problem is the response interceptor is called only once (for the https://localhost:5001/swagger/v2/swagger.json file) and it is not called for any API messages.
Is it possible to intercept all swagger API messages?
According to this post it should be possible: https://stackoverflow.com/a/46892528/1882699, but this does not work for me for some reason.
This configuration of Swagger UI works for me is in this post.
The difference is this line:
dom_id: '#swagger-ui',
When this line is used the interceptor intercepts every message. Without this line the interceptor catches only the first message.
While invoking same MVC controller action method successively with different inputs noticed in the server logs during the second call still holding the input parameter values that were passed during the first call.
Below is the calling procedure in angular
var oDat = {
dob: '',
tob: '',
latlng: '',
timezone: ''
};
oDat.dob = dob.split('T')[0].split('-')[2] + '|' + dob.split('T')[0].split('-')[1] + '|' + dob.split('T')[0].split('-')[0];
oDat.tob = dob.split('T')[1].split(':')[0] + '|' + dob.split('T')[1].split(':')[1] + '|' + '0';
oDat.latlng = latlng;
oDat.timezone = tz;
//let headers = new Headers({ 'Content-Type': 'application/json; charset=utf-8' });
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/json; charset=utf-8');
return this.http.post(this.apiUrl9, JSON.stringify(oDat), {headers: headers}).pipe(
map(this.extractData),
catchError(this.handleError)
);
UPDATE
The issue remained same even after disable http cache
headers.append('Cache-control', 'no-cache');
headers.append('Cache-control', 'no-store');
headers.append('Expires', '0');
headers.append('Pragma', 'no-cache');
I resolved the server cache issue by setting below attribute right above the action method
[OutputCache(NoStore = true, Duration = 0)]
here is the link that helped Prevent Caching in ASP.NET MVC for specific actions using an attribute
In Worklight I am trying to sent an HTTP request (via HTTP adapter) that includes parameters with Greek letters. However the encoding applied, alters the Greek letters to hieroglyphics. Does anyone know how I can make the request send Greek characters?
var request =
'<?xml version="1.0" encoding="UTF-8"?>'
+ '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '
+ 'xmlns:test="">'
+ '<soapenv:Header/>'
+ '<soapenv:Body>'
+ '<test:getAnalysis>'
+ '<request>'
+ '<invoiceId>' + invoiceId + '</invoiceId>'
+ '</request>'
+ '</test:getAnalysis>'
+ '</soapenv:Body>'
+ '</soapenv:Envelope>';
var options = {
method : 'post',
returnedContentType : 'xml',
path : getPath(),
body: {
content: request.toString(),
contentType: 'text/xml; charset=utf-8',
},
};
return WL.Server.invokeHttp(options).Envelope.Body;
The above request works fine. UTF-8 was the only thing needed. The issue with the encoding appeared when I tried calling the adapter via eclipse. When the adapter was called via the application, the parameters were sent using the correct encoding.
I want to give dynamic action name in Url.action through javascript.
// I want to change Index name by dynamic
$.ajax({
url: '#Url.Action("Index", "Home")',
type: "Post",
data: { Surveyid: surveyid, Category: catcode },
success: function (data) {
window.location.href = data.Url
}
like
var x="xxxx";
#Url.Action(x,"Home") -> not working throws error
#Url.Action(x.toString(),"Home") -> not working
then how can i ?
Url.Action is server generated, whereas it seems you want to change the action on the browser. What you can do is tokenize the Action, get Url.Action to generate the tokenized URL, and then substitute this in js:
var jsUrl = '#Url.Action("##", "Home")'; // ## is the token
$.ajax({
url: jsUrl.replace('##', someDynamicAction),
...
(You may need to do the same for the controller)
Edit
My conscience has gotten the better of me - doing this isn't a good idea, given that any invalid action name (or a change in the Controller or Action names) will only be picked up at run time e.g. with 404 errors.
The number of controllers and actions that you need to ajax to should be finite, and T4MVC has already solved this kind of issue.
You can create the urls to the various links:
var urlToIndex = '#Url.Action(MyControllerAssembly.Index.Home())))';
var urlToOtherAction = ...
... etc for all actions needed in the 'switch' for ajax call.
and then choose the appropriate URL for your ajax call. (T4MVC also has methods Url.JavaScriptReplacableUrl and Ajax.ActionLink although for slightly different scenarios)
Best way to use urls in your mvc application is that you define a global app_url in layout page like following:
_Layout.cshtml
<script>
var app_root = '#Url.Content("~/")';
</script>
and use in content page
any_page that inherited from _Layout.cshtml
$.ajax({
url: app_root + 'Home/Index', // or url: app_root + 'Home/' + x
something odd in your example, but I believe what you are trying to do is this
function axajThis(numberthing,path) {
var newUrl = "htttp://somplace/"+path;
/* and what ever the number x is doing */
$.ajax({
url: newUrl,
type: "Post",
data: ....
});
};
}
axajThis(x,"Home");
Little more info needed on what 'x' is.
Hope there is some out there that can help!,
While debugging a WCF service that a phonegap application connects to it seems to post twice.
When the application runs normally no Break points etc it all works fine and i only receive 1.
It appears to me that ajax reposts itself if no response is returned from the server after a few seconds.
I will need to confirm this threw wireshark but just wanted to know if anyone else has come accross this before.
$.ajax({
type: "POST",
url: ServicePATH ,
data: JSON.stringify({ objs: arrayobj, parm2: var2, parm3: var3, parm4: 1 }),
contentType: "application/json",
dataType: "json",
success: function (data, textStatus, jqXHR) {
CallonSuccess(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('error ' + textStatus);
console.log('XMLHttpRequest ' + XMLHttpRequest);
var str = '';
for (prop in XMLHttpRequest) {
str += "prop " + prop + " value :" + XMLHttpRequest[prop] + "\n"; //Concate prop and its value from object
}
console.log(str);
console.log('errorThrown ' + errorThrown);
console.log('passing ' + JSON.stringify({ objs: arrayobj, parm2: var2, parm3: var3, parm4: 1 }));
}
}).done(function () { console.log('Finished ajax'); });
Thanks Lmac
Perhaps no solution (see update below) for you but the same behaviour here.
Without the jquery Mobile framework everything works okay, with the framework embedded it fetches my json file a second time. In Chrome's Console you can see it under Network: GET status 200 and GET status 304 (not modified).
I have the option to throw out jQuery Mobile and I surely will. But would be also interested in knowing what's happening there.
UPDATE:
I had the xmlhttprequest within the $(document).ready(function() { }); It seems as if both jQuery and jQuery Mobile react to that.
If I put the script at the end of the site and make my xmlhttprequest outside the ready-method it fetches my json file only once.