Pregunta

Déjame comenzar diciendo que puede parecerse simple, pero lo estoy encontrando extremadamente difícil.

He hecho un script de búsqueda que usa PHP y para buscar un resultado se vería así

search.php?term=alice&submit=Submit

problema estándar .. El problema es que uso un SPI con AJAX y PHP, por lo que mis resultados tendrían que cargar dinámicamente en un DIV, mientras que aún mantengo el valor de hash, como para no perder la página, el usuario había visitado el usuario anterior a la búsqueda. .

jquery.history.js es el complemento que uso para el soporte de botón Atrás, lo que requiere que los enlaces sean así:

<a href="#home">Home Page</a>

Esto cargaría 'home.html' en un DIV llamado Pagecontent. Por lo que sé, no hay forma de llamar a los archivos PHP a menos que desarrolle un pequeño hack, que tengo,

Aquí está mi JavaScript / JQery para mi formulario de búsqueda:

<script language="JavaScript">
$(document).ready(function() { 
    // bind form using ajaxForm 
    $('#search1').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#pageContent', 

        // success identifies the function to invoke when the server response 

        success: function() { 
            $('#pageContent'); 
            var hash = '#search.php?term='+($('#query').val()+'&submit=Submit').replace(/ /g, '+');
            var stripped = hash.replace(/(<([^>]+)>)/ig,""); 
            update(window.location.hash = stripped);

        } 

    }); 
});

</script>

heres la forma:

<form id="search1" action="search.php" method="post">
    <input id="query" type="text" name="term" />
    <input type="submit" name="submit" value="Submit" />
    </form>

Mi problema es esto: IVE intentado this.form.reset(); Esto: Restablecimiento de un formulario de múltiples etapas con jQuery , aún ninguno de esto funciona. por favor ayúdame si conoces una forma de hacer esto ...

¿Fue útil?

Solución

$('#query').val(DefaultValue);

with this u can set your value to whatever you want, like blank: '';

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top