This is my second day with jQuery & AJAX. I've done as much googleing as I know to do for this. But, with not knowing what I'm looking for, I'm lost. This is very close to working, but I can't quite figure it out.
I'm trying to use my company's ("xyz") API, and it won't work when I have the form action = a url to the page.
I've done this many times in PHP. The APIs URL is:
xyz.com/getdata.php?from=tt&isbn={variable_int}
Can someone give me a hand?
<form method="post" action="xyz.com/getdata.php" id="searchForm">
<input type="text" name="isbn" placeholder="Search..." />
<input class="myaccount" id="doSearch" name="doSearch" type="submit" value="Search" />
</form>
<div id="result"></div>
{literal}
<script>
// attach a submit handler to the form
$("#searchForm").submit(function(event) {
// stop form from submitting normally
event.preventDefault();
// get some values from elements on the page:
var $form = $( this ),
term = $form.find( 'input[name="isbn"]' ).val(),
url = $form.attr( 'action' );
// Send the data using post and put the results in a div
// $.开发者_运维技巧post( url, { doSearch: "Search", isbn: term } ,
$.post( url, { from: "tt", isbn: term } ,
function( data ) {
var content = $( data );
$( "#result" ).html( content );
}
);
});
</script>
Thanks so much (in advance)!
Cross-domain with an AJAX request is not as easy as it seems.
Here's an interesting link you should read: http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
I'm not sure but if you use the string below
xyz.com/getdata.php?from=tt&isbn={variable_int}
the method to send data is "get". The form uses the method "post". I think there is a conflict.
精彩评论