After Ajax request session is expired in php - ajax

I have created REST API in codeigniter. This API I am using on my codeigniter website and It's working fine. I have created one JavaScript for call API using ajax. It's also working fine but problem is that after calling ajax If refresh the page or tired to open another page of website it's send to me login page. I don't know why my session is expired ?
I have check in chrome developer tools. After calling ajax clicked page return 302 status.
$.ajax({
url: rest_url,
dataType: 'jsonp',
success: function(data){
//some code
}
});

This problem is caused by session ID regeneration during AJAX requests
If you upgrade your codeigniter , it will be good because we have fixed this error with codeigniter. If you can't , you can get a view in how we have fixed it here Fix of this bug in github. As you can see you just need to change the if condition on this file system/libraries/Session.php. I think that my answer will be usefull for you.

Related

Can Someone Editing my ajax code

when I am using ajax in laravel to post if the button is clicked very fast and to much it will cause some of the posts to finish updating the database faster than others, which cuases a counter field in my database to have wrong data, I am using async:false, my question is can a user edit my ajax in there browser and send the ajax code with out async:false?
maybe it can be done, use post request so it can't be injected because it checks CSRF session.

Unable to Successfully Update Page Content via ajax

I have a mobile version of a website built in jQuery mobile and living on a dedicated "m.myurl" subdomain. The full desktop version of the site is in Wordpress. My goal is to have updates entered via Wordpress to the desktop site to show up dynamically on the mobile site as well. I am generating the page content from the individual pages of the desktop site via JSON feeds, and have confirmed that the JSON feeds are good (i.e.: if I enter their URL into a browser, I get a good JSON object). However, the AJAX call on the jQuery mobile site refuses to work. I have debugged to the point that I am not receiving any errors in my console, but when I attempt to log the response from the AJAX call to troubleshoot, it consistently shows in the log as undefined, so I am not receiving known good JSON objects.
The functions I'm using to make the AJAX call are as follows:
function processResponse(response){
var update = $(response).find('content');
$('.content').append($(update).html());
};//ends processResponse
function processJSON(url){
$.ajax({
url: url,
data: null,
success: processResponse,
dataType: 'jsonp',
});//ends ajax
};//ends processJSON
I've set the three JSON URL's equal to variables, but have tried calling the function with the URL passed in instead of the variable, to no effect. The 'processJSON" function is called within the content div of each page section of the jQuery mobile index.html file within a $(document).ready.I'm using 'jsonp' as the dataType, as I assume that calling from a subdomain to a main-level domain would be considered a cross-domain call. That said, I'm trying to get this to work locally, and haven't placed it on a test server yet.
Any assistance is appreciated. Thanks!

How to avoid a changePage immediately after ajax post with javascript

Help!
I am using jquery mobile to submit a JSON string to my rails app via an ajax post. The string contains some data that I send via the following ajax call in a JS file:
$.ajax({
url: "http://" + MyURL + ".json",
type: "POST",
data: JSON.stringify(this.form),
dataType: "json",
contentType: "application/json",
success: onSaveSuccess,
error: onFailure,
complete: onComplete
});
This code works, but as soon as I press the button to submit the form, it changes the page to my home page (NOT EVEN THE PREVIOUS PAGE). I want to set this post up so that it doesn't change pages until I tell it to (in either the success or complete functions). I don't want the user to be thrown around different pages after submitting the post. Instead, I want to show my upload spinner until it is done, and then I will redirect them to a specific page.
Does anyone know how to do this?
My login screen uses a (nearly) identical ajax script, and it does exactly what I want. I am assuming that is because there is no page to go "back" to. I don't understand this behavior, so if anyone does, your advice would be appreciated.

Ajax file upload in MVC 4 using jquery.form.js

I am using MVC . My scenario is like i need to post file and forms variables to controller.
I tried AjaxSubmit which works in all browsers except for IE. It shows "access is denied".
$(".WW_Register_Form").ajaxSubmit({ url: url, type: 'post', enctype: 'multipart/form-data'});
My requirements are to post a file and post form parameters in ajax.
Is there any other jquery plugin by which i can accomplish this?
You are probably receiving the access denied error due to restrictions on XMLHttpRequests over cross-domains.
Are you trying to access another domain that isn't of same-origin? Even something as simple as removing the www off of www.formsubmit.com could cause an issue with your requests and the browser does not see this as a same-origin
Have a look here https://developer.mozilla.org/en-US/docs/JavaScript/Same_origin_policy_for_JavaScript and here http://en.wikipedia.org/wiki/Same_origin_policy for clarification.
My suggestion is to make sure that you are trying to contact an application/script that is of same-origin.

getJSON and ajax not working in IE

I am trying to get getJSON working on my IE, but I read that IE doesn't support it that well. So I decided to use ajax instead.
My code is:
$.ajax({
dataType: 'json',
url: 'http://openexchangerates.org/latest.json',
success: function(data)
{
alert('done');
}
});
Thanks
You cannot make crossdomain ajax calls. Take a look at the top post at this SO post. If you have a specific need to do so, you need to use some sort of sockets. This can be file_get_contents in php or another server-side language
I had this problem just the other day. Internet Explorer doesn't like you doing cross-domain requests with AJAX.
I solved it by having a server-side script do the cross-domain API request, and then call the result of that script in my AJAX call.

Resources