javascript - Jquery Get Response Data Error -



javascript - Jquery Get Response Data Error -

i have code calls buy.php , makes purchase , shows results.

store.php

<h4 class="result">result:</h4> function buy(id) { $.ajax({ method: "get", url: "buy.php?id="+id+"", success: function (data) { $(".result").html(data); } }); }

buy.php

(after many check finally)

echo 'purchase successful!';

or

echo 'purchase failed!';

when store.php calls buy.php

this shows jquery makes request not buy.php page (store.php) , when phone call purchase function content on current page duplicates. why doing so? help?

the url alternative ajax url, not url. javascript case-sensitive.

function buy(id) { $.ajax({ method: "get", url: "buy.php?id="+id+"", // here ^ success: function (data) { $(".result").html(data); } }); }

side note: if id number, code work, there's improve way supply id value: using data option:

function buy(id) { $.ajax({ method: "get", url: "buy.php", // <== alter here data: {id: id}, // <== , here success: function (data) { $(".result").html(data); } }); }

the nice thing using data alternative (with object, above) jquery ensure parameters correctly uri-encoded. again, doesn't matter number (if id number), it's habit into, because matters quite lot strings.

javascript php jquery html forms

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -