score:14
From the comments:
I'm posting to another site
Aha! There's your issue. Browsers block AJAX to external websites for security reasons. Sorry, but you're not going to issue that request via an XHR request.
If the other website wants you to communicate with them, they could expose this part of the site via JSON-P, which works something like this:
- My site adds
<script src="http://othersite.com/signon.js?username=foo&password=bar&callback=myCallback">
to the source code (yeah, it's messy to use GET for this, but JSON-P can't work any other way), and creates a function namedmyCallback
to handle the response data. - The other site signs in, then returns something like
myCallback({success: false, errorMessage: "Incorrect password, try again!"})
- That script is run on my site, calls
myCallback
, and everything is happy.
JSON-P is a powerful protocol, but only works if the remote site agrees to it. Still, if they do, jQuery has a nice shortcut for it: just set dataType: "jsonp"
and it will handle the whole callback thing for you.
But if you're not closely involved with this website, that's unlikely to happen, and you'll probably just be stuck with having to give up on this kind of cross-site interaction. Sorry, but this kind of cross-domain policy is critical to online security. (I don't want other sites issuing requests to bankofamerica.com
on my behalf, kthx.)
Similar question
- Difference between jquery form submission and remote form submission in Rails 3
- JSP, jquery and HTML : use form post data in ajax call.
- Difference between jQuery form slider, script slider?
- Dealing with difference between JavaScript and PHP's months when using a JQuery countdown timer
- what's the difference between dom of jquery and "native" dom?
- jQuery post form and callback
- using JQuery and Ajax to post a form
score:-2
when using POST method you should ,in your case, Post your data as JSON
var url = "https://mywebsite/signon.php";
$.ajax({
url: url,
type: 'POST',
dataType: 'html',
data: {
harv_acc : accountnumber,
harv_eml : email
},
success: function (data) {
closePopup("div_PleaseWait");
alert(data);
//window.location = encodeURI('<%= Url.Action("DownloadDocument", "Documents") %>?DocumentID=' + documentID + '&DownloadType=' + downloadType + '&DownloadPath=' + data);
}
});
NOTE : i used dataType : JSON
score:0
Try sending ther data as a key:value object. This is an example from the jQuery docs
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
Update: as user Matchu pointed out, this is not the problem, as the data will be converted into a query string anyway, as stated in the jQuery docs:
"The data option can contain either a query string of the form key1=value1&key2=value2, or a map of the form {key1: 'value1', key2: 'value2'}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. "
So yeah, some rash answering on my part there. At least I learned something! ;)
score:0
Cross domain ajax requests are not supported by browser. But there is another way to get around this.
You can use JSONP for cross-domain requests. It is easy to use and allows you to request anything (as long as it is in JSON format) from any server/script that supports the callback. The good thing about JSONP is that it works in older browsers too.
The only serious limitation seems to be that it always uses the HTTP GET method
Can you please check with this too.
score:1
The first parameter passed to your complete
function will be a jqXHR
object, which is a wrapper around the browser's XMLHttpRequest
object. A more convenient way to handle the response is to use the done
method:
var url = "https://mywebsite/signon.php";
$.ajax({
url: url,
type: 'POST',
dataType: 'html',
data: "harv_acc=" + accountnumber + "&harv_eml=" + email
}).done(function(data) {
closePopup("div_PleaseWait");
alert(data);
});
Related Query
- Can't find difference between Fetch and JQuery Ajax
- Jquery Conflict between Mega-Menu and MailChimp form
- What is the difference between change in jQuery and JavaScript?
- Sending data from the form to an email with jQuery ajax and redirect to another page with passing POST variables not work
- Calculate difference of months and semi-month difference between two dates using Jquery
- Formatting form data using JQuery for AJAX POST and access easily in Laravel (or PHP)?
- What is difference between these two jQuery selectors: 'select option:selected' and 'select :selected'?
- Form Validation using JavaScript and jQuery
- Append Form And Elements jQuery Mobile
- Jquery difference between two columns table
- post and trigger a php file in server using jquery ajax post method
- Ajax prevent form action and post form data
- Get the variables from Jquery UI form and post?
- How to stop JQuery submit then run ajax validation and then submit form
- php form action and jquery validation executing at once
- Simulate a select and submit form with jQuery without a select
- Contact form php and jquery
- form action in html when jquery and ajax are used?
- jquery validation working in one form and not in the other form
- Clone form fields and maintain jquery functionality
- Different HTTP POST behaviors from Objective C and from JQuery
- Returning and parsing json array via php and jquery post
- form submit jquery v javascript difference
- jQuery Dynamic form submission and Ajax call
- What's the best way to select an element between one element and one of its ancestor using jQuery
- Process dynamically created web form with JQuery and PHP
- jQuery max value of fields and min in form
- Conflict between google map and jquery tab
- How to use JQuery.noConflict() to fix conflict between JQuery and bootstrap in rails 3.2.12?
- Jquery - How to read a txt file and append into a form
- Interaction between XMLDocument and JQuery .append()
- Jquery find all form elements with a certain data- and then find the matching label and change it's contents
- Getting date with jQuery and saving it to MySQL with a PHP form
- What is the difference between `add`and `setup` in jQuery special events?
- jQuery conflict between jPanelMenu and TweenMax/superscrollorama
- jquery mobile switch between grid and list view
- jquery toggle and nested form
- jQuery form plugin passing context in request and response
- how can i use the jquery validation plugin manually...ex. respond to a button click and not to a form post?
- post file by jquery and save it using c#
- difference between two menu links on jquery navbar
- Dilemma between keeping my code with pure js + jQuery AJAX calls or getting rid of every client script and rewriting the code in .NET only
- C# MVC and jQuery AJAX - having trouble with Form Posts and history issues in general
More Query from same tag
- How to read and display a text file in to a <pre>, preserving line breaks, tabs and new lines?
- count value of single subject from checkbox's data-id which is in string format separated by commas
- Hide fields based on selection from dropdown
- get the name and image of the user who is leaving comment
- How do I append an array to a wordfilter (greasemonkey + jquery)?
- Jquery for when navbar is at top of screen become sticky not working
- How does web image caching work and why does this website I created only work properly offline
- Rails don't add new table row with ajax/jquery
- Click handler not working when putting element inside include
- How to change a variable value in jQuery if an item's siblings do not have a class (within mixitup plugin)?
- Masking 1000 ajax post request with better performance
- HTML5 Video Autoplay In Slider Issue
- jQuery click() and append() not responding on iterated divs
- Jquery validate allows form submit even if there are errors
- jQuery not working on page load in an Apache Cordova application
- How to get url from dropdown select with javascript
- Will there be a performance increase if using custom attribute selectors instead of long mixed class/tag selectors with jQuery?
- Decode HTML entities with Regex
- JQuery - how to use the hover() event on a list of DIVs?
- Using jQuery to change src on all classes except for current click
- how to submit a variable along with array variable in jquery to php and return them?
- Use quick-view in fancybox
- Toggle only one onClick imageChange at a time (toggle all other images to original state)?
- jqueryui tabs crashing IE
- Updating and Reading Cookies Dynamically
- jquery-confirm plugin - submit form confirmation
- Want to fetch td select box selected value using jQuery in vertical way
- JQuery between limit regular expression checker?
- CSS fade in fade out gives a weird blink
- Separate table columns into different tables