IE 7 redirect after jQuery ajax calls

I have the following code in my file for loading a div with HTML from an AJAX call:

$('#searchButton').click( function() { $('#inquiry').load('/search.php?pid=' + $('#searchValue').val()); }); 

This works fine in Firefox and Google Chrome, but whenever I do a search in IE, I get redirected back to index.php. I grabbed the URL from Firebug and pasted it into IE, and the redirect does not happen, I just get the output that needs to be returned.

I also tried changing it to a $ .get () request and a full $ .ajax () request, but still the same redirect.

+4
source share
5 answers

More fun. I have an input text and a button wrapped in this form:

 <form onSubmit="return false;"> [HTML] </form> 

and IE seems to ignore the return false. I tried modifying the jQuery function to look like Steve, but it was still impenetrable.

I removed the form tags and took care of this.

+1
source

IE handles default events differently (also beware of getting into a text box). IE triggers the default event handler. If searchButton is a HREF link, this reloads the current page. You can try setting href to "javascript: void (0)" or do something like:

 $('#searchButton').click( function(e) { $('#inquiry').load('/search.php?pid=' + $('#searchValue').val()); e.preventDefault(); }); 
+2
source

set the form action attribute to a javascript function (for example, your search processing function) or "return false"

MSIE runs the form action when you press enter

0
source

Your function should return false to prevent the button submit action. I don't know how jQuery works.

0
source

You must prohibit the use of the default, for example, as follows.

 var searchbutton = $('#searchButton'); var inquirysearchvalue = $('#inquiry').load('/search.php?pid=' + $('#searchValue'); searchbutton.click( function(e) { inquirysearchvalue.val()); e.preventDefault(); }); 
0
source

Source: https://habr.com/ru/post/1277536/


All Articles