Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax returns the whole page

I have a jquery-ajax function that sends data to a php script and the problem is with the return value, it returns the whole page instead of single value.

Thank you for your time and help.

$("#ajaxBtn").click(function(){   var inputText = $("#testText").val();    $.ajax({ type: "POST",     url: "index.php",     data: "testAjax="+inputText,     dataType: "html",     success: function(html){       alert(html);     }   }); });          
like image 946
Sophia Gavish Avatar asked Apr 06 '10 15:04

Sophia Gavish


People also ask

What is jqXHR in AJAX?

The jqXHR Object. The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method.

How to make AJAX call from jQuery?

The ajax() method in jQuery is used to perform an AJAX request or asynchronous HTTP request. Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.

What is jQuery AJAX functions?

ajax() method allows you to send asynchronous http requests to submit or retrieve data from the server without reloading the whole page. $. ajax() can be used to send http GET, POST, PUT, DELETE etc.

What is dataType in AJAX call?

dataType The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response. "text": A plain text string. So you want contentType to be application/json and dataType to be text : $.


1 Answers

That's how it works. You're requesting index.php via AJAX, so you'll get whatever the contents of index.php are.

If you want a particular value, make a new PHP page that outputs just that value, and request that URL's contents instead.

like image 172
ceejayoz Avatar answered Sep 22 '22 13:09

ceejayoz