function refre...">

Jquery.get / .post doesn't work on 7 or 8, works fine in ff

I have basically this on the page:

<script type="text/javascript">
function refresh_context() {
    $("#ajax-context").html("Searching...");
    $.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function(xml) {
        $("#ajax-context").html($("display", xml).text());
        $("#context").val($("context", xml).text());
    }, 'xml');
}
$(document).ready(function() {
    $("#username").blur(refresh_context);
});
</script>

<input type="text" name="username" id="username" maxlength="255" value="" />
<input type="hidden" name="context" id="context" value=""/>
<div id="ajax-context"></div>

What should it do (and works fine in Firefox), when you enter the username in the #username field, it will run / ajax / ldap _search.php? Cn = $ username, which our company searches for ldap for the username and returns it The original context and formatted version of the context as follows:

<result>
    <display>Staff -&gt; Accounting -&gt; John Smith</display>
    <context>cn=jsmith,ou=Accounting,ou=Staff,ou=Users,o=MyOrg</context>
</result>

The formatted version (display) goes into div # ajax-context and goes to hidden input #context. (Also, → is actually "& gt;" (without spaces)).

However, in IE, the div stays on “Search ...”, and the hidden input value remains blank.

.get, .post . , .get, , :

$.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function() {
    alert("Check");
});

, IE script.

: "$ (document).ready(function() {",.blur , .

2: , apache2 :

10.135.128.96 - - [01/May/2009:10:04:27 -0500] "GET /ajax/ldap_search.php?cn=i_typed_this_in_IE HTTP/1.1" 200 69
+3
10

ldap_search.php. ( , -):

header("content-type:application/xml-xhtml;charset=utf-8");

IE, :

header("content-type:application/xml;charset=utf-8");

, IE.

+7

:

$("#username").blur(refresh_context);

To:

$(function(){
    $("#username").blur(refresh_context);
});

blur, .

Edit:

> XML?

+4

'xml'

jQuery.get(url, [data], [callback], [type])

$.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function() {
    alert("Check");
},'xml');
+2

, Ajax- ?

- Fiddler Ajax.

, jQuery, DOM $(document).ready. , , DOM, , , div "..."

<script type="text/javascript">
function refresh_context() {
    $("#ajax-context").html("Searching...");
    $.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function(xml) {
        $("#ajax-context").html($("display", xml).text());
        $("#context").val($("context", xml).text());
    }, "xml"); // As pointed out, you should specify the return type
}
$(document).ready(function() {
    $("#username").blur(refresh_context);
});
</script>
+1

$. $. ajax, , , .

, :

$.ajax({
    type: 'GET',
    url: "/ajax/ldap_search.php",
    data: {cn: $("#username").val()},
    success: function(response) { /* do something here */ },
    error: function(xhr, type, exception) { alert("Error: " + type); }
})

.

+1

, xml - html ajax-return. ( "Content-Type: ; = UTF-8" ); .

+1

:

$.post("/welcome/add_mail", function(data){
       alert('ok');   
});

url IE7:

$.post("http://localhost/welcome/add_mail", function(data){
       alert('ok');   
});
+1

$.get/$. post . jquery: a) , , b) .

.

0

$( "display", xml).text()

, : $(xml).find( "display" ). text()

, ? , ? ,

function refresh_context() {
    $("#ajax-context").html("Searching...");
    $.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function(xml) {
        $("#ajax-context").html($("display", xml).text());
        $("#context").val($("context", xml).text());
    }, "xml"); // As pointed out, you should specify the return type
}

function refresh_context() {
    $("#ajax-context").html("Searching...");
    $.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function(xml) {
        var displayXml = $("display", xml).text();
        $("#ajax-context").html(displayXml);
        var contextXml = $("context", xml).text();
        $("#context").val(contextXml);
    }, "xml"); // As pointed out, you should specify the return type
}

script.

0

, JSON. $.ajax , , URL-. :

$.getJSON('',{ ajax: "addressPicker",OID:pickIDNo,s:pickVal}, function(data) {

, URL '' '?' . URL- , URL-.

0

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


All Articles