Ajax file upload in MVC 4 using jquery.form.js - asp.net-mvc-3

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.

Related

After Ajax request session is expired in php

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.

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!

Wordpress Ajax deeplink gives 404

Hi Folks,
my first post here, thanks for any help i got already throught reading before.
I am working on a wordpress projekt. And it seems i am missing the overview on my problem.
I use ajax to recieve additional product data. http:url/product/additional_ajax_data...
This works fine, except direct call of the ajax urls. Direct call of a ajax url gives
a 404 not found.
Please dont give instructions like: add 200 ok to header... Cause the project will
consist of some thousand pages and work arounds like this are a no go...
Aditional infos: the urls have no ajax hash tag... And the content will dynamicly loaded depending on last url fragment
I found the solution:
To prevent Wordpress of 404 when calling a ajax url directly, add rewrite endpoints to the system.
You can follow the post from Jon Cave on Wordpress:
http://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
Works also on custom post_types and custom taxonomys, keep an eye on the type for wich you want to register a custom endpoint rewrite (that may depends on your options from your post type, page type etc...).
If you are sure that url is correct and file is there, check if permissions on file are not too strict. Also check .htaccess to make sure it doesn't black certain file extensions to be loaded directly

AJAX GET-request appears in URL bar after refreshing the page in Tomcat that gets restarted

My web app runs under Tomcat, it uses AJAX requests very intensively, and during the development process I have to redeploy the web app intensively too. After the redeployment I usually simply refresh the page knowing that the user session is dropped, but I always get to the scenario described below:
Go to some page, a really big page with many JS-scripts included, that actually makes those intensive AJAX requests.
Stop Tomcat or redeploy the web app.
Refresh the page.
Enter the credentials in the sign-in form to authenticate.
Suddenly get the last AJAX request response in the browser window and the AJAX request URL in the URL bar.
Wow... It looks strange for me that AJAX request URLs appear in the URL bar along with their response in the web page display area. This actually happens to Firefox and Chrome (haven't tested it in other browsers). Unfortunately, I cannot reproduce the same behavior in a simple page written from scratch. Frankly speaking, I don't really understand what happens to such requests and why do browsers "think" if AJAX requests/responses are entered in URL bar by user...
Your possible explanations or hints for such a strange behavior are very and very appreciated. Thanks!
(Perhaps it can help: All AJAX requests are performed with jQuery 1.4.2)
I'm very sorry, as I understood later, the question is not complete, because there was another pitfall I didn't mention, so no one couldn't answer the question in principle. The reason of the bug was hiding in the... <body onunload="..."> tag definition. That was quite unexpected, but that code contained some AJAX request that must be invoked when a user leaves the page. I only realized that the authenicating module (FORM, j_security_check) returned a response (HTTP 302) containing the Location header - so that was the reason why browsers did redirects.
The exact scenario was like that:
Open the page containing <body onunload="some_ajax_here">.
Log out the app using another tab so you could stay at the same page.
Refresh the page so some ajax could be invoked - this AJAX request is not now allowed because it's a secured part of the application (you get the forwarded content of the login page).
Enter the credentials and now oops you get to the result of some ajax directly in the browser window.
As the quick fix, and I hope the final one, I added another request following that AJAX request:
$.ajax({
async: true,
method: "GET",
url: document.location.pathname + document.location.search
});
So the HTML page script simply makes self-page request the last one - j_security_check returns the Location referring the last used HTML page, and the redirect works fine. Perhaps my explanation is not clear and may be not complete or even full of mistakes, but it looks like that in general. I'm very sorry once again, and thank you #ChristopherSchultz!

HTTP Post By AJAX

I want to post some ad to CraigList webiste using this URL. https://post.craigslist.org/nyc/S/fud/mnh/all I know AJAX is a solution which can perform where there is no same origin policy restriction.
The unique thing about this URL is that it modifies the action attribute of the form every time you refresh the page and I can't just post to a single static URL. I wonder is there a way I can automate this URL using AJAX?
I am using JQuery and know how to post a URL but this is headache.
You won't be able to use AJAX as it violates the same origin policy. You can use a regular POST, but you will have to parse the page for the hidden fields etc. to make it work.
Craigslist has gone into a lot of problem to make automated posting very difficult, so I wouldn't bother.

Resources