Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed some help combining 2 jQuery scripts and behaviors
    text
    copied!<p>Ι need to use a combination of the following 2 scripts but despite all the combinations I've done so far, I fail to get it to work 100%.</p> <p>I use a colorbox to display products detail pages in which there is a form with various fields for adding the items to the cart. Upon submitting the form, I want to show an alert and then close the colorbox so that the underlying page (that opened the colorbox in the forst place) stays as is.</p> <p>With this script </p> <pre><code>$("#productadd").submit(function(){ // WORKS FINE EXCEPT THE ENCODING $.post( $(this).attr('action'), $(this).serialize(), function(data){ alert('Product was added to your order'); $().colorbox.close(); }); </code></pre> <p>everything works fine except for the encoding which in my case is iso-8859-7 (greek). If I use this script then encoding is ok but the post is being made with the default behaviour, redirection to the url defined in the form's action.</p> <pre><code> $("#productadd").submit(function(){ //ENCODING OK, COLORBOX.CLOSE() AND ALERT FAIL $.ajax({ data: data, type: "POST", url: $(this).attr('action'), dataType: 'json', beforeSend : function(xhr) { xhr.setRequestHeader('Accept', "text/html; charset=iso-8859-7"); }, success: function(json) { alert('Product added to cart!'), $().colorbox.close(), itemAddCallback(json); }, error: function (xhr, textStatus, errorThrown) { $("#error").html(xhr.responseText); } }); </code></pre> <p>If there's a jQuery equivalent for xhr.setRequestHeader('Accept', "text/html; charset=iso-8859-7") I'd be more than happy to use it. Also, what do I declare as data: so I dont get a 'data is not defined' error? (despite the error, date submits fine).</p> <p><strong>UPDATE</strong>: After various suggestions from those who answered so far, this is what my code looks like: </p> <pre><code> $("#productadd").submit(function(){ $.ajax({ data: $(this).serialize(), type: "POST", url: $(this).attr('action'), dataType: 'text', mimeType: "text/html; iso-8859-7", success: function() { alert('Item added to your order'), $().colorbox.close(); }, error: function (xhr, textStatus, errorThrown) { $("#error").html(xhr.responseText); } }); </code></pre> <p>My only problem is that although it submits and displays the alert etc, the submitted data is encoded in utf-8 instead of iso-8859-7, any ideas? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload