Sensa Touch 1.1 with JSONP Object calls only the first time - caching

I am trying to get an answer from a server through an Ext.util.JSONP.request. The code works fine and calls the callback function, but only for the first time. I have searched a lot about it, but the solutions I saw do not provide a solution for me. My Code is:
Ext.util.JSONP.request({
method: 'GET',
callbackKey: 'callback',
callback: function(data){
alert('data');
},
url: myUrl,
});
I tried adding changing params for every call in callbackparams as well as at the end of the url with ?param=myParam, being myParam different in every call.
I tried adding disableCaching: true
I tried to add to the response:
response.setHeader("Cache-Control", "no-store");
I also tried calling the url directly from the browser and this works fine, every time I call I receive a new answer, thus it is not a problem from the server.
I do not know what else could I test. Could you please help me?
Thanks a lot in advance.

Related

Render a view while Ajax expects a response

I am building an express project, using ejs as a view engine, and AJAX for front-end http calls.
When I post a request such this:
$.ajax({
type: 'POST',
data: {'nickname' : $('#nickname').val()},
contentType: 'application/x-www-form-urlencoded',
url: 'http://localhost:5000/create',
success: function(data) {
$('#message').text("Unkwon error");
},
error: function(data){
$('#message').text('Something went wrong, check connection!');
}
The Ajax keeps waiting for a response, which I am not willing to give, as I just want to render a view as follows :
app.post('/create', urlencodedParser, (req, res)=>{
let code = unique.generate(rooms);
res.render('chat', {'nickname' : req.body.nickname, 'code' : code}
Any ideas how can I work around this?
After some research, I found a way to do it.
Basically, I can just tell the Ajax to attach the document sent from rendering to the html body
$('body').html(data);
Surprisingly, this works event with Ejs dynamic tags.
I know it's not the best way to do it, but it's the only one I found till now.
EDIT 1:
After few months, I realized the solution is simple as just changing the Location using javascript
window.location.replace(`http://localhost:5000/newRequest`);
Now, I could handle this new request separately on the server.
EDIT 2:
After couple years now, I realized a GET request might have solved the problem in a single round trip.

ASP.Net MVC 3 VB.Net Ajax request gives me a 403 forbidden error

I've been trying to make an Ajax call from my vbhtml page and I can't seem to get it working. I've been researching for a while now my problem but I can't seem to find an answer, maybe it is because I don't actually know exactly what to ask.
In my code i am trying to send the value that was selected in a DataGrid from DataTables.net so that i can retrieve the information related to the selection and put it in some textboxes.
Anyways, I've been getting a 403 frobidden error when doing the ajax
Here's my View code
function ShowInfos(selected) {
$.ajax({
type: "POST",
url: "/Controllers/TelephonieController.vb/Show",
data: '{nomEcran: "' + selected + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
Here's my Controller code
<System.Web.Services.WebMethod()> _
Public Shared Function Show(nomEcran As String) As String
Return "allo"
End Function
(Sorry it's a bit in french)
This is the error it gives me
POST http://localhost:4390/Controllers/TelephonieController.vb/Show 403 (Forbidden)
I've only just started with Web so I might be a total newbie with this, but i have checked on the Web and people have been saying to take out ContenType or DataType and I've done both, I even tried sending and empty String with the Data but I can't seem to get it to work.
A bit off topic sort of, I tried an other way of doign ajax which is exactly this : http://msdn.microsoft.com/en-us/library/dd381533(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
the problem is I can't seem to understand how I should send or could send a javascript variable to the controller.
If someone has a better way of doing things than what I am doing right now feel free to comment so I can learn.
As you are using asp.net mvc3, you can try #Url.Action(...
url: "#Url.Action('Telephony','Show')",
You just need to provide controller and action name. Dont know why are you using TelephonieController.vb in url this isnt web form.
Though i dont have experience in vb, but still feels that vb would work like c#

Send ONE Javascript variable to PHP via AJAX

I've been looking around the forums without a solution to my problem. It's pretty simple, really, and I'd appreciate it if you could explain your answer if you would be so kind.
I'm new to AJAX and Javascript, and I need to send one variable from my javascript code and basically "convert" it into php. Here's what I have so far:
var selected = rowData.ID
jQuery.ajax({
url: "test.php",
type: 'POST',
data: { selected },
cache: false
});
I use this selected value further down in the code. I use PHP to display the (value of selected).
"vars": [
"(value of selected)"
],
However, I can't seem to make my ajax request work and send the variable to my PHP file. Here's what my PHP file looks like:
$row = $_POST["selected"];
Thanks in advance for the help.
try replacing your "data:" with this:
data: { 'selected': selected },
So this is very delayed answer, but I was having trouble getting a variable to send too. I'm not using php, but saw loads of examples like vlscanner gave, but who knows why it didn't work.
I stumbled across this explanation of how to send multiple parameters, and it works just as lovely for sending one parameter.
http://weblog.west-wind.com/posts/2012/May/08/Passing-multiple-POST-parameters-to-Web-API-Controller-Methods
multiple:
data: JSON.stringify({ Album: album, User: user, UserToken: userToken }),
or just one:
data: JSON.stringify({ Album: album}),
I'm no expert on timing,efficiency and all that, and it's possible that JSON.stringify adds unnecessary bulk and there is possibly some valid reason that sending data without the JSON.stringify didn't work. However, if you are in a bind and need something to work, this might help those of us still asking this question.
I'm suspecting that mine did not work because I was sending it to an asp method that likely requires the parameters to come as a JSON string. I have to research that next. Every step is a new discovery.

Why is my json request erroring instead of succeeding?

Here is my debugging method that goes to the error block instead of the success block.
function removerelationship(reference_related_id_var) {
if ($('##relationships').attr('id') != undefined) {
$.ajaxSetup({cache:false});
$.ajax({
url: 'index.cfm?action=reference.confirmjson',
dataType: 'json',
data: {reference_id:reference_id_var, reference_related_id:reference_related_id_var},
success: function(){alert("I PASSED");},
error: function(){alert("I FAILED");}
});
But this is my response from calling reference.confirmjson:
{"MESSAGE":"Are You Sure You Want To Remove The Relationship Between References 744094 and 1200?","CONFIRMED":true}
Is there some reason this would still take me to the error block?
Thanks.
Make sure you have debug output turned off for the AJAX request . I explain it a bit better at http://orangexception.com/post/7308110027/remove-debug-output-from-ajax-requests-in-coldfusion
The error case would be called if any status other than a 200 is being returned. Take a peek at the response in Firebug or a similar tool. If CF is also throwing an error further down the request, it would return a 500. This can help you determine if you need to check the CF application log for an error.
Edit: Also, check the raw response. Firebug does an awesome job at dropping the trailing CF error and just showing the properly formatted JSON, which could be confusing if an error was thrown.

JQuery ajax calls not working in Firefox browser

I am trying to test Jquery ajax calls in Firefox but it it not working. I mean my server is not receiving any requests. But when I test in IE8 it works fine. Here is my ajax call:
$("#getWeatherReport").click(function(){
$cityName = "New York";
$.ajax({
type: "POST",
dataType:"xml",
url: "http://localhost:8080/Test/WeatherServlet",
data: "cityName="+$cityName,
success: function(data) {
alert($("report", data).text());
},
error: function(xhr, textStatus, errorThrown) {
alert('ERROR['+xhr.statusText+']');
}
});
});
It is not even calling error function. And from my server code(java) I am setting content type as "text/xml".
Any suggestions?
Your string is not correctly serialized, I'm not sure if that's the issue, but it may be and it's definitely a potential one for later, try this for an immediate test:
var $cityName = "New+York";
As a more permanent solution, pass data as an object, like this:
data: {cityName: $cityName},
Have you installed Firebug?
Your best bet would be to install Firebug, which comes with a console that'll notify you of any javascript errors. You can also use it (via the "Net" tab) to monitor all requests made by your page.
From what I can see, your code looks OK (other than the possible issue pointed out by #Nick Craver)
Also, why the '$' on your cityName variable? The '$' prefix in Javascript is meant to be reserved for machine-generated code (so that it has no chance of conflicting with user code).
try installing firebug plugin in ff :: https://addons.mozilla.org/en-US/firefox/addon/1843/
Then check the :::: Net Tab >> All selected
Refresh the page and see is your ajax call actually getting called. If yes is there any syntax error in the call or any variable null error. If all is fine then you can think of further issues
Usually, when I end up with a parseerror that means that the return header type is wrong or that somehow the server sent extra data with the response. For instance, if I'm looking to get JSON back and I get the JSON and some HTML from x-debug.
Also, The OPTIONS request is for cross-domain requests which is what #Nick was alluding to.
A helpful link to get you started.

Resources