2013-11-22 133 views
0

我有一个表格页面1我想解析它的变量,以调用AJAX调用page 2。 ajax调用由onload事件触发。将php变量添加到ajax调用

场景:

第1页

<form id="form1"method="GET" action="page2">//send the variables to page 2 
<input type="text" name="Place" value="city"> 
<input type="text" name="Type" value="room"> 
<input type="submit"></form> 

第2页

<form name="myform2" id="myform2" method="GET"> 
<input type="text" name="Place" value="<?php echo $_GET[Place] ?>">// 
<input type="text" name="type" value="<?php echo $_GET[Type] ?>"> 
<button id="submit2"type="submit" value="submit2" name="submit2" onclick="return ss()"> 

JS1

$(document).ready(function(){ // load file.php on document ready  
    function sssssss2(page){ 
      var form2 = document.myform2; 
      var dataString1 = $(form2).serialize() + '&page=' + page; 
     ({ 
     type: "GET", 
     url: "file.php",// 
     data: dataString1, 
     success: function(ccc){ 
      $("#search_results").html(ccc); 
     }});} 
    sssssss2(1) ; 
    $('#search_results .pagination li.active').live('click',function(){ 
     var page = $(this).attr('p'); 
     sssssss2(page);     
    }); 
}); 

JS2

function sss() {//serialize the form each time submitted. 
    var form2 = document.myform2; 
    var dataString1 = $(form2).serialize(); 
    $.ajax({ 
     type:'GET', 
     url: "file.php", 
     cache: false, 
     data: dataString1, 
     success: function(data){ 
      $('#search_results').html(data); 
     } 
    }); 
    return false; 
} 

问题是file.php好好尝试采取变量“城市”和“房间” .I想解析2变量file.php当第2页加载第一次。

Hw解析文档加载page2上的那些变量?

+0

它在js1中缺少'$ .ajax'。应该是'$ _GET ['Place']','$ _GET ['Type']' – Don

回答

0

不应对和类型在引号像

<input type="text" name="Place" value="<?php echo $_GET['Place'] ?>">// 
<input type="text" name="type" value="<?php echo $_GET['Type'] ?>"> 
0

你们面前“方法”错过blankspace以及在“类型”属性:

<form id="form1"method="GET" action="page2"> 
<button id="submit2"type="submit" value="submit2" name="submit2" onclick="return ss()"> 

在这里,你会错过的action属性:

<form name="myform2" id="myform2" method="GET"> 

这是错误的²因为你错过了;你把一个常数我在指数的字符串的nstead:

<?php echo $_GET[Type] ?> 

正确:

<?php echo $_GET['Type']; ?> 

在JS1你错过$.ajax({ +上线4 ({是不正确的无论是。

了解valid HTML, proper PHP以及一些我建议的基础知识,它不能以这种方式工作,尤其是不能跨平台兼容。

您不能从100个教程中复制脚本,并希望它们能够工作,您必须知道每个命令和代码行以及它的功能。