简体   繁体   English

jQuery + Ajax无法接收html按钮值

[英]Jquery + Ajax Can't receive html button value

here is my jquery function: 这是我的jQuery函数:

function showNewWindow(){
    $('#result').slideDown('slow');
    $("#result").html('<div id=resim><center><img src="loading.gif"></center></div>');
    $.ajax({
        type:'GET',
        url:'windowLoader.php',
        data:$('#windowName').serialize(),
        success:function(response){
            $("#result").html(response)
        }
    })
}

What i want to do: I have a menu, which include lot's of pages in it. 我想做什么:我有一个菜单,其中包含很多页面。 I want it to load the page the user selected without refreshes in browser. 我希望它加载用户选择的页面而不在浏览器中刷新。

My form has an id as you can understand. 您可以理解,我的表格有一个ID。 if i store the get information in a hidden html input, it parses the first input and doesn't see others. 如果我将get信息存储在隐藏的html输入中,它将解析第一个输入,而看不到其他输入。 (every page has different names) So i thought that, if i store the data in buttons, the problem will be solved. (每个页面都有不同的名称)所以我认为,如果我将数据存储在按钮中,则将解决该问题。 But this time; 但是这次 no GET sent to windowLoader.php. 没有GET发送到windowLoader.php。

I don't want to write different functions in jquery or seperate if's in php because it will be a silly thing to do. 我不想在jQuery中编写其他函数,也不想在php中编写其他函数,因为这样做是很愚蠢的。

Could anyone please help me about that trouble? 有人可以帮我解决这个麻烦吗?

You should be using $.get(...) instead of $.ajax(...), as this method is meant to be at a very low level. 您应该使用$ .get(...)而不是$ .ajax(...),因为此方法的级别很低。 try this: 尝试这个:

function showNewWindow(){
$('#result').slideDown('slow');
$("#result").html('<div id=resim><center><img src="loading.gif"></center></div>');
var myData = $('#windowName').serialize();
$.get("windowLoader.php", 
    myData, 
    function(data){
        $('#result').html(data);
    }, 
    "html");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM